40 require
'../../main.inc.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formpropal.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/modules/propale/modules_propale.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/lib/propal.lib.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
52 if (!empty($conf->project->enabled)) {
53 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
57 if (!empty($conf->variants->enabled)) {
58 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
62 $langs->loadLangs(array(
'companies',
'propal',
'compta',
'bills',
'orders',
'products',
'deliveries',
'sendings',
'other'));
63 if (!empty($conf->incoterm->enabled)) {
64 $langs->load(
'incoterm');
66 if (!empty($conf->margin->enabled)) {
67 $langs->load(
'margins');
74 $socid =
GETPOST(
'socid',
'int');
75 $action =
GETPOST(
'action',
'aZ09');
76 $cancel =
GETPOST(
'cancel',
'alpha');
77 $origin =
GETPOST(
'origin',
'alpha');
78 $originid =
GETPOST(
'originid',
'int');
79 $confirm =
GETPOST(
'confirm',
'alpha');
80 $lineid =
GETPOST(
'lineid',
'int');
81 $contactid =
GETPOST(
'contactid',
'int');
82 $projectid =
GETPOST(
'projectid',
'int');
83 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
86 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
87 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
88 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
97 $extrafields->fetch_name_optionals_label($object->table_element);
100 if ($id > 0 || !empty($ref)) {
101 $ret = $object->fetch($id, $ref);
103 $ret = $object->fetch_thirdparty();
112 $hookmanager->initHooks(array(
'propalcard',
'globalcard'));
114 $usercanread = $user->hasRight(
"propal",
"lire");
115 $usercancreate = $user->hasRight(
"propal",
"creer");
116 $usercandelete = $user->hasRight(
"propal",
"supprimer");
118 $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->close)));
119 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)));
120 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->send)));
122 $usercancreateorder = $user->hasRight(
"commande",
"creer");
123 $usercancreateinvoice = $user->hasRight(
"facture",
"creer");
124 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
125 $usercancreateintervention = $user->hasRight(
'ficheinter',
'creer');
126 $usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
128 $permissionnote = $usercancreate;
129 $permissiondellink = $usercancreate;
130 $permissiontoedit = $usercancreate;
133 if (!empty($user->socid)) {
134 $socid = $user->socid;
144 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
149 if (empty($reshook)) {
150 $backurlforlist = DOL_URL_ROOT.
'/comm/propal/list.php';
152 if (empty($backtopage) || ($cancel && empty($id))) {
153 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
154 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
155 $backtopage = $backurlforlist;
157 $backtopage = DOL_URL_ROOT.
'/comm/propal/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
163 if (!empty($backtopageforcancel)) {
164 header(
"Location: ".$backtopageforcancel);
166 } elseif (!empty($backtopage)) {
167 header(
"Location: ".$backtopage);
173 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
175 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
177 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
180 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
184 if ($object->id > 0) {
185 if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) {
191 GETPOST(
'date_deliverymonth',
'int'),
192 GETPOST(
'date_deliveryday',
'int'),
193 GETPOST(
'date_deliveryyear',
'int')
195 $date_delivery_old = (empty($object->delivery_date) ? $object->date_livraison : $object->delivery_date);
196 if (!empty($date_delivery_old) && !empty($date_delivery)) {
207 $difference = $date_delivery - $old_date_delivery;
208 if ($difference != 0) {
209 $object->date_livraison = $date_delivery;
210 $object->delivery_date = $date_delivery;
211 foreach ($object->lines as $line) {
212 if (isset($line->date_start)) {
213 $line->date_start = $line->date_start + $difference;
215 if (isset($line->date_end)) {
216 $line->date_end = $line->date_end + $difference;
223 $result = $object->createFromClone($user, $socid, (
GETPOSTISSET(
'entity') ?
GETPOST(
'entity',
'int') :
null), (
GETPOST(
'update_prices',
'aZ') ?
true :
false));
225 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
228 if (count($object->errors) > 0) {
235 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
237 $result = $object->delete($user);
239 header(
'Location: '.DOL_URL_ROOT.
'/comm/propal/list.php?restore_lastsearch_values=1');
242 $langs->load(
"errors");
245 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
247 $result = $object->deleteline($lineid);
250 $object->line_order(
true);
252 $langs->load(
"errors");
256 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
258 $outputlangs = $langs;
259 if (!empty($conf->global->MAIN_MULTILANGS)) {
261 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
262 $outputlangs->setDefaultLang($newlang);
264 $ret = $object->fetch($id);
266 $object->fetch_thirdparty();
268 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
271 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
273 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
275 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
276 $result = $object->valid($user);
278 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
279 $outputlangs = $langs;
281 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
282 $newlang =
GETPOST(
'lang_id',
'aZ09');
284 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
285 $newlang = $object->thirdparty->default_lang;
287 if (!empty($newlang)) {
289 $outputlangs->setDefaultLang($newlang);
291 $model = $object->model_pdf;
292 $ret = $object->fetch($id);
294 $object->fetch_thirdparty();
297 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
300 $langs->load(
"errors");
301 if (count($object->errors) > 0) {
307 } elseif ($action ==
'setdate' && $usercancreate) {
312 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
316 $result = $object->set_date($user, $datep);
317 if ($result > 0 && !empty($object->duree_validite) && !empty($object->fin_validite)) {
318 $datev = $datep + ($object->duree_validite * 24 * 3600);
319 $result = $object->set_echeance($user, $datev, 1);
323 } elseif (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
324 $outputlangs = $langs;
326 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
327 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) $newlang = $object->thirdparty->default_lang;
328 if (!empty($newlang)) {
330 $outputlangs->setDefaultLang($newlang);
332 $model = $object->model_pdf;
333 $ret = $object->fetch($id);
335 $object->fetch_thirdparty();
338 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
341 } elseif ($action ==
'setecheance' && $usercancreate) {
344 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
345 $outputlangs = $langs;
347 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
348 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) $newlang = $object->thirdparty->default_lang;
349 if (!empty($newlang)) {
351 $outputlangs->setDefaultLang($newlang);
353 $model = $object->model_pdf;
354 $ret = $object->fetch($id);
356 $object->fetch_thirdparty();
359 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
364 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
365 $result = $object->setDeliveryDate($user,
dol_mktime(12, 0, 0,
GETPOST(
'date_livraisonmonth',
'int'),
GETPOST(
'date_livraisonday',
'int'),
GETPOST(
'date_livraisonyear',
'int')));
369 } elseif ($action ==
'setref_client' && $usercancreate) {
371 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
375 } elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled) && $usercancreate) {
377 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
378 } elseif ($action ==
'add' && $usercancreate) {
380 $object->socid = $socid;
381 $object->fetch_thirdparty();
385 $duration =
GETPOST(
'duree_validite',
'int');
388 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DatePropal")),
null,
'errors');
392 if (empty($duration)) {
393 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ValidityDuration")),
null,
'errors');
399 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
410 if ($object->fetch(
GETPOST(
'copie_propal',
'int')) > 0) {
412 $object->datep = $datep;
413 $object->date = $datep;
414 $object->date_livraison = $date_delivery;
415 $object->delivery_date = $date_delivery;
416 $object->availability_id =
GETPOST(
'availability_id');
417 $object->demand_reason_id =
GETPOST(
'demand_reason_id');
418 $object->fk_delivery_address =
GETPOST(
'fk_address',
'int');
419 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
420 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
421 $object->duree_validite = $duration;
422 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
423 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
424 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
425 $object->fk_account =
GETPOST(
'fk_account',
'int');
428 $object->socid =
GETPOST(
'socid',
'int');
429 $object->contact_id =
GETPOST(
'contactid',
'int');
430 $object->fk_project =
GETPOST(
'projectid',
'int');
431 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
432 $object->author = $user->id;
433 $object->user_author_id = $user->id;
434 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
435 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
437 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
438 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
444 $object->ref_client =
GETPOST(
'ref_client');
445 $object->datep = $datep;
446 $object->date = $datep;
447 $object->date_livraison = $date_delivery;
448 $object->delivery_date = $date_delivery;
449 $object->availability_id =
GETPOST(
'availability_id',
'int');
450 $object->demand_reason_id =
GETPOST(
'demand_reason_id',
'int');
451 $object->fk_delivery_address =
GETPOST(
'fk_address',
'int');
452 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
453 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
455 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
456 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
457 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
458 $object->fk_account =
GETPOST(
'fk_account',
'int');
459 $object->contact_id =
GETPOST(
'contactid',
'int');
460 $object->fk_project =
GETPOST(
'projectid',
'int');
461 $object->model_pdf =
GETPOST(
'model');
462 $object->author = $user->id;
463 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
464 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
465 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
466 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
468 $object->origin =
GETPOST(
'origin');
469 $object->origin_id =
GETPOST(
'originid');
472 if (!empty($conf->multicurrency->enabled)) {
473 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
477 $ret = $extrafields->setOptionalsFromPost(
null, $object);
485 if ($origin && $originid) {
487 $element = $subelement = $origin;
488 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
489 $element = $regs [1];
490 $subelement = $regs [2];
494 if ($element ==
'order') {
495 $element = $subelement =
'commande';
497 if ($element ==
'propal') {
498 $element =
'comm/propal';
499 $subelement =
'propal';
501 if ($element ==
'contract') {
502 $element = $subelement =
'contrat';
504 if ($element ==
'inter') {
505 $element = $subelement =
'ficheinter';
507 if ($element ==
'shipping') {
508 $element = $subelement =
'expedition';
511 $object->origin = $origin;
512 $object->origin_id = $originid;
515 $object->linked_objects [$object->origin] = $object->origin_id;
516 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
517 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
520 $id = $object->create($user);
524 $classname = ucfirst($subelement);
525 $srcobject =
new $classname($db);
527 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
528 $result = $srcobject->fetch($object->origin_id);
531 $lines = $srcobject->lines;
532 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
533 $srcobject->fetch_lines();
534 $lines = $srcobject->lines;
538 $num = count($lines);
539 for ($i = 0; $i < $num; $i++) {
540 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
541 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
544 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
548 if ($lines[$i]->date_debut_prevue) {
549 $date_start = $lines[$i]->date_debut_prevue;
551 if ($lines[$i]->date_debut_reel) {
552 $date_start = $lines[$i]->date_debut_reel;
554 if ($lines[$i]->date_start) {
555 $date_start = $lines[$i]->date_start;
560 if ($lines[$i]->date_fin_prevue) {
561 $date_end = $lines[$i]->date_fin_prevue;
563 if ($lines[$i]->date_fin_reel) {
564 $date_end = $lines[$i]->date_fin_reel;
566 if ($lines[$i]->date_end) {
567 $date_end = $lines[$i]->date_end;
571 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
576 if (method_exists($lines[$i],
'fetch_optionals')) {
577 $lines[$i]->fetch_optionals();
578 $array_options = $lines[$i]->array_options;
581 $tva_tx = $lines[$i]->tva_tx;
582 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
583 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
586 $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent,
'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
597 if ($result > 0 && $lines[$i]->product_type == 9) {
598 $fk_parent_line = $result;
604 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
620 $id = $object->create($user);
625 if (
GETPOST(
'contactid') > 0) {
626 $result = $object->add_contact(
GETPOST(
'contactid'),
'CUSTOMER',
'external');
633 if (!empty($conf->global->PROPOSAL_AUTO_ADD_AUTHOR_AS_CONTACT)) {
634 $result = $object->add_contact($user->id,
'SALESREPFOLL',
'internal');
637 setEventMessages($langs->trans(
"ErrorFailedToAddUserAsContact"),
null,
'errors');
645 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
646 $outputlangs = $langs;
648 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
649 $newlang =
GETPOST(
'lang_id',
'aZ09');
651 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
652 $newlang = $object->thirdparty->default_lang;
654 if (!empty($newlang)) {
656 $outputlangs->setDefaultLang($newlang);
658 $model = $object->model_pdf;
660 $ret = $object->fetch($id);
661 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
667 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
680 } elseif ($action ==
'classifybilled' && $usercanclose) {
684 $result = $object->classifyBilled($user, 0,
'');
695 } elseif ($action ==
'confirm_closeas' && $usercanclose && !
GETPOST(
'cancel',
'alpha')) {
697 if (!(
GETPOST(
'statut',
'int') > 0)) {
698 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CloseAs")),
null,
'errors');
700 } elseif (
GETPOST(
'statut',
'int') == $object::STATUS_SIGNED ||
GETPOST(
'statut',
'int') == $object::STATUS_NOTSIGNED) {
702 if ($object->statut == $object::STATUS_VALIDATED) {
705 $result = $object->closeProposal($user,
GETPOST(
'statut',
'int'),
GETPOST(
'note_private',
'restricthtml'));
712 $locationTarget =
'';
714 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
717 !$error &&
GETPOST(
'statut',
'int') == $object::STATUS_SIGNED &&
GETPOST(
'generate_deposit',
'alpha') ==
'on'
718 && ! empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
720 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
723 $forceFields = array();
726 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
733 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
743 if ($deposit && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
744 $ret = $deposit->fetch($deposit->id);
745 $outputlangs = $langs;
747 if ($conf->global->MAIN_MULTILANGS) {
749 $outputlangs->setDefaultLang($deposit->thirdparty->default_lang);
750 $outputlangs->load(
'products');
753 $result = $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
760 if ($locationTarget) {
761 header(
'Location: ' . $locationTarget);
770 } elseif ($action ==
'confirm_reopen' && $usercanclose && !
GETPOST(
'cancel',
'alpha')) {
776 $result = $object->reopen($user, 1);
788 } elseif ($action ==
'import_lines_from_object'
789 && $user->rights->propal->creer
793 $fromElement =
GETPOST(
'fromelement');
794 $fromElementid =
GETPOST(
'fromelementid');
795 $importLines =
GETPOST(
'line_checkbox');
797 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
798 if ($fromElement ==
'commande') {
800 $lineClassName =
'OrderLine';
801 } elseif ($fromElement ==
'propal') {
802 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
803 $lineClassName =
'PropaleLigne';
805 $nextRang = count($object->lines) + 1;
808 foreach ($importLines as $lineId) {
809 $lineId = intval($lineId);
810 $originLine =
new $lineClassName($db);
811 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
812 $originLine->fetch_optionals();
813 $desc = $originLine->desc;
814 $pu_ht = $originLine->subprice;
815 $qty = $originLine->qty;
816 $txtva = $originLine->tva_tx;
817 $txlocaltax1 = $originLine->localtax1_tx;
818 $txlocaltax2 = $originLine->localtax2_tx;
819 $fk_product = $originLine->fk_product;
820 $remise_percent = $originLine->remise_percent;
821 $date_start = $originLine->date_start;
822 $date_end = $originLine->date_end;
824 $info_bits = $originLine->info_bits;
825 $fk_remise_except = $originLine->fk_remise_except;
826 $price_base_type =
'HT';
828 $type = $originLine->product_type;
830 $special_code = $originLine->special_code;
831 $origin = $originLine->element;
832 $origin_id = $originLine->id;
834 $fk_fournprice = $originLine->fk_fournprice;
835 $pa_ht = $originLine->pa_ht;
836 $label = $originLine->label;
837 $array_options = $originLine->array_options;
838 $situation_percent = 100;
840 $fk_unit = $originLine->fk_unit;
841 $pu_ht_devise = $originLine->multicurrency_subprice;
843 $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $date_start, $date_end, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise, $fk_remise_except);
861 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
864 $actiontypecode =
'AC_OTH_AUTO';
865 $triggersendname =
'PROPAL_SENTBYMAIL';
866 $autocopy =
'MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
867 $trackid =
'pro'.$object->id;
868 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
872 if ($action ==
'modif' && $usercancreate) {
873 $object->setDraft($user);
875 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
877 $outputlangs = $langs;
878 if (!empty($conf->global->MAIN_MULTILANGS)) {
880 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
881 $outputlangs->setDefaultLang($newlang);
883 $ret = $object->fetch($id);
885 $object->fetch_thirdparty();
887 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
889 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
890 if (
GETPOST(
"remise_id",
"int")) {
891 if ($object->id > 0) {
892 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
898 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
900 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
901 $vat_rate = str_replace(
'*',
'', $vat_rate);
902 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
903 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
904 foreach ($object->lines as $line) {
905 $result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc,
'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
907 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
909 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
910 $remise_percent = str_replace(
'*',
'', $remise_percent);
911 foreach ($object->lines as $line) {
912 $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc,
'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
914 } elseif ($action ==
'addline' && $usercancreate) {
920 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
921 if ($prod_entry_mode ==
'free') {
925 $idprod =
GETPOST(
'idprod',
'int');
931 if (empty($remise_percent)) {
936 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
937 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
939 if (is_array($extralabelsline)) {
941 foreach ($extralabelsline as $key => $value) {
942 unset($_POST[
"options_".$key]);
946 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
947 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
951 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'') {
952 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
955 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
956 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
960 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
961 if ($combinations =
GETPOST(
'combinations',
'array')) {
965 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
966 $idprod = $res->fk_product_child;
968 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
974 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
978 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
988 if (!empty($idprod) && $idprod > 0) {
990 $prod->fetch($idprod);
992 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
997 if (empty($tva_tx)) {
1002 $pu_ht = $prod->price;
1003 $pu_ttc = $prod->price_ttc;
1004 $price_min = $prod->price_min;
1005 $price_base_type = $prod->price_base_type;
1008 if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
1009 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
1010 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
1011 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
1012 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
1013 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1014 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
1015 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
1017 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
1018 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
1021 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1023 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
1027 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
1029 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
1032 if (count($prodcustprice->lines) > 0) {
1033 $pu_ht =
price($prodcustprice->lines[0]->price);
1034 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
1035 $price_min =
price($prodcustprice->lines[0]->price_min);
1036 $price_base_type = $prodcustprice->lines[0]->price_base_type;
1037 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1038 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1039 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1041 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1042 if (empty($tva_tx)) {
1047 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
1049 if ($prod->prices_by_qty[0]) {
1054 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
1055 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1059 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1060 $pu_ht = $priceforthequantityarray[
'unitprice'];
1062 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1068 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1070 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
1075 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
1076 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1080 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1081 $pu_ht = $priceforthequantityarray[
'unitprice'];
1083 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1091 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
1092 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
1095 if (!empty($price_ht) || $price_ht ===
'0') {
1097 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1098 } elseif ($tmpvat != $tmpprodvat) {
1101 if ($price_base_type !=
'HT') {
1102 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1104 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1111 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1112 $outputlangs = $langs;
1114 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1115 $newlang =
GETPOST(
'lang_id',
'aZ09');
1117 if (empty($newlang)) {
1118 $newlang = $object->thirdparty->default_lang;
1120 if (!empty($newlang)) {
1121 $outputlangs =
new Translate(
"", $conf);
1122 $outputlangs->setDefaultLang($newlang);
1125 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
1127 $desc = $prod->description;
1131 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1135 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1136 $desc = $product_desc;
1138 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1154 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
1157 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1158 $outputlangs = $langs;
1160 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
1161 $newlang =
GETPOST(
'lang_id',
'alpha');
1163 if (empty($newlang)) {
1164 $newlang = $object->thirdparty->default_lang;
1166 if (!empty($newlang)) {
1167 $outputlangs =
new Translate(
"", $conf);
1168 $outputlangs->setDefaultLang($newlang);
1169 $outputlangs->load(
'products');
1171 if (!empty($prod->customcode)) {
1172 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1174 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1177 if (!empty($prod->country_code)) {
1178 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
1181 if (!empty($prod->customcode)) {
1182 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1184 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1187 if (!empty($prod->country_code)) {
1188 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
1195 $type = $prod->type;
1196 $fk_unit = $prod->fk_unit;
1200 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1201 $tva_tx = str_replace(
'*',
'', $tva_tx);
1202 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1203 $desc = $product_desc;
1206 $fk_unit =
GETPOST(
'units',
'alpha');
1207 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1218 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
1219 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
1226 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
1227 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
1231 $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, min($rank, count($object->lines) + 1), 0,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit,
'', 0, $pu_ht_devise);
1236 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1238 $outputlangs = $langs;
1239 if (!empty($conf->global->MAIN_MULTILANGS)) {
1240 $outputlangs =
new Translate(
"", $conf);
1241 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1242 $outputlangs->setDefaultLang($newlang);
1244 $ret = $object->fetch($id);
1246 $object->fetch_thirdparty();
1248 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1251 unset($_POST[
'prod_entry_mode']);
1253 unset($_POST[
'qty']);
1254 unset($_POST[
'type']);
1255 unset($_POST[
'remise_percent']);
1256 unset($_POST[
'price_ht']);
1257 unset($_POST[
'multicurrency_price_ht']);
1258 unset($_POST[
'price_ttc']);
1259 unset($_POST[
'tva_tx']);
1260 unset($_POST[
'product_ref']);
1261 unset($_POST[
'product_label']);
1262 unset($_POST[
'product_desc']);
1263 unset($_POST[
'fournprice']);
1264 unset($_POST[
'buying_price']);
1265 unset($_POST[
'np_marginRate']);
1266 unset($_POST[
'np_markRate']);
1267 unset($_POST[
'dp_desc']);
1268 unset($_POST[
'idprod']);
1269 unset($_POST[
'units']);
1271 unset($_POST[
'date_starthour']);
1272 unset($_POST[
'date_startmin']);
1273 unset($_POST[
'date_startsec']);
1274 unset($_POST[
'date_startday']);
1275 unset($_POST[
'date_startmonth']);
1276 unset($_POST[
'date_startyear']);
1277 unset($_POST[
'date_endhour']);
1278 unset($_POST[
'date_endmin']);
1279 unset($_POST[
'date_endsec']);
1280 unset($_POST[
'date_endday']);
1281 unset($_POST[
'date_endmonth']);
1282 unset($_POST[
'date_endyear']);
1290 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1294 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1303 $vat_rate = str_replace(
'*',
'', $vat_rate);
1304 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1305 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1320 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1321 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1323 if (is_array($extralabelsline)) {
1325 foreach ($extralabelsline as $key => $value) {
1326 unset($_POST[
"options_".$key]);
1331 $special_code =
GETPOST(
'special_code',
'int');
1337 $productid =
GETPOST(
'productid',
'int');
1338 if (!empty($productid)) {
1340 $res = $product->fetch($productid);
1342 $type = $product->type;
1344 $price_min = $product->price_min;
1345 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1346 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
1350 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 - $remise_percent / 100) <
price2num($price_min)))) {
1351 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
1356 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1360 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1368 if (empty($user->rights->margins->creer)) {
1369 foreach ($object->lines as &$line) {
1370 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1371 $fournprice = $line->fk_fournprice;
1372 $buyingprice = $line->pa_ht;
1380 $result = $object->updateline(
GETPOST(
'lineid',
'int'), $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description,
'HT', $info_bits, $special_code,
GETPOST(
'fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options,
GETPOST(
"units"), $pu_ht_devise);
1385 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1387 $outputlangs = $langs;
1388 if (!empty($conf->global->MAIN_MULTILANGS)) {
1389 $outputlangs =
new Translate(
"", $conf);
1390 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1391 $outputlangs->setDefaultLang($newlang);
1393 $ret = $object->fetch($id);
1395 $object->fetch_thirdparty();
1397 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1400 unset($_POST[
'qty']);
1401 unset($_POST[
'type']);
1402 unset($_POST[
'productid']);
1403 unset($_POST[
'remise_percent']);
1404 unset($_POST[
'price_ht']);
1405 unset($_POST[
'multicurrency_price_ht']);
1406 unset($_POST[
'price_ttc']);
1407 unset($_POST[
'tva_tx']);
1408 unset($_POST[
'product_ref']);
1409 unset($_POST[
'product_label']);
1410 unset($_POST[
'product_desc']);
1411 unset($_POST[
'fournprice']);
1412 unset($_POST[
'buying_price']);
1414 unset($_POST[
'date_starthour']);
1415 unset($_POST[
'date_startmin']);
1416 unset($_POST[
'date_startsec']);
1417 unset($_POST[
'date_startday']);
1418 unset($_POST[
'date_startmonth']);
1419 unset($_POST[
'date_startyear']);
1420 unset($_POST[
'date_endhour']);
1421 unset($_POST[
'date_endmin']);
1422 unset($_POST[
'date_endsec']);
1423 unset($_POST[
'date_endday']);
1424 unset($_POST[
'date_endmonth']);
1425 unset($_POST[
'date_endyear']);
1432 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1433 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1435 } elseif ($action ==
'classin' && $usercancreate) {
1437 $object->setProject(
GETPOST(
'projectid',
'int'));
1438 } elseif ($action ==
'setavailability' && $usercancreate) {
1440 $result = $object->set_availability($user,
GETPOST(
'availability_id',
'int'));
1441 } elseif ($action ==
'setdemandreason' && $usercancreate) {
1443 $result = $object->set_demand_reason($user,
GETPOST(
'demand_reason_id',
'int'));
1444 } elseif ($action ==
'setconditions' && $usercancreate) {
1446 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
1447 } elseif ($action ==
'setremisepercent' && $usercancreate) {
1448 $result = $object->set_remise_percent($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
1449 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
1450 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
1451 } elseif ($action ==
'setmode' && $usercancreate) {
1453 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
1454 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
1456 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
1457 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
1459 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
1460 } elseif ($action ==
'setbankaccount' && $usercancreate) {
1462 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
1463 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
1465 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
1466 } elseif ($action ==
'setwarehouse' && $usercancreate) {
1468 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
1469 } elseif ($action ==
'update_extras') {
1473 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1478 $result = $object->insertExtraFields(
'PROPAL_MODIFY');
1485 $action =
'edit_extras';
1489 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1490 if ($action ==
'addcontact') {
1491 if ($object->id > 0) {
1494 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1498 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1501 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1502 $langs->load(
"errors");
1503 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1508 } elseif ($action ==
'swapstatut') {
1510 if ($object->fetch($id) > 0) {
1511 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1515 } elseif ($action ==
'deletecontact') {
1517 $object->fetch($id);
1518 $result = $object->delete_contact($lineid);
1521 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1530 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
1531 $permissiontoadd = $usercancreate;
1532 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1544 if (!empty($conf->project->enabled)) {
1548 $title = $langs->trans(
'Proposal').
" - ".$langs->trans(
'Card');
1549 $help_url =
'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
1555 if ($action ==
'create') {
1556 $currency_code = $conf->currency;
1562 $res = $soc->fetch($socid);
1566 if (!empty($origin) && !empty($originid)) {
1568 $element = $subelement = $origin;
1570 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1571 $element = $regs[1];
1572 $subelement = $regs[2];
1575 if ($element ==
'project') {
1576 $projectid = $originid;
1579 if ($element ==
'order' || $element ==
'commande') {
1580 $element = $subelement =
'commande';
1582 if ($element ==
'propal') {
1583 $element =
'comm/propal';
1584 $subelement =
'propal';
1586 if ($element ==
'contract') {
1587 $element = $subelement =
'contrat';
1589 if ($element ==
'shipping') {
1590 $element = $subelement =
'expedition';
1595 $classname = ucfirst($subelement);
1596 $objectsrc =
new $classname($db);
1597 $objectsrc->fetch($originid);
1598 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1599 $objectsrc->fetch_lines();
1601 $objectsrc->fetch_thirdparty();
1603 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
1604 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1606 $soc = $objectsrc->thirdparty;
1608 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1609 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1610 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1611 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1612 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1613 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
1616 $objectsrc->fetch_optionals();
1617 $object->array_options = $objectsrc->array_options;
1619 if (!empty($conf->multicurrency->enabled)) {
1620 if (!empty($objectsrc->multicurrency_code)) {
1621 $currency_code = $objectsrc->multicurrency_code;
1623 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1624 $currency_tx = $objectsrc->multicurrency_tx;
1629 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1630 $currency_code = $soc->multicurrency_code;
1635 if ($soc->fk_warehouse > 0) {
1636 $warehouse_id = $soc->fk_warehouse;
1638 if (!empty($conf->stock->enabled) && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1639 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1640 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1642 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1643 $warehouse_id = $user->fk_warehouse;
1647 print
'<form name="addprop" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1648 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1649 print
'<input type="hidden" name="action" value="add">';
1650 if ($origin !=
'project' && $originid) {
1651 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1652 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1653 } elseif ($origin ==
'project' && !empty($projectid)) {
1654 print
'<input type="hidden" name="projectid" value="'.$projectid.
'">';
1659 print
'<table class="border centpercent">';
1662 print
'<tr class="field_ref"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td class="valuefieldcreate">'.$langs->trans(
"Draft").
'</td></tr>';
1665 print
'<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans(
'RefCustomer').
'</td><td class="valuefieldcreate">';
1666 print
'<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:
GETPOST(
'ref_client')).
'"></td>';
1670 print
'<tr class="field_socid">';
1671 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1672 $shipping_method_id = 0;
1674 print
'<td class="valuefieldcreate">';
1675 print $soc->getNomUrl(1,
'customer');
1676 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1678 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1679 $shipping_method_id = $soc->shipping_method_id;
1683 print
'<td class="valuefieldcreate">';
1684 print
img_picto(
'',
'company').$form->select_company(
'',
'socid',
'((s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1)',
'SelectThirdParty', 0, 0,
null, 0,
'minwidth300 maxwidth500 widthcentpercentminusxx');
1686 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1687 print
'<script type="text/javascript">
1688 $(document).ready(function() {
1689 $("#socid").change(function() {
1690 console.log("We have changed the company - Reload page");
1691 var socid = $(this).val();
1693 $("input[name=action]").val("create");
1694 $("form[name=addprop]").submit();
1699 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
1706 print
'<tr class="field_contactid"><td class="titlefieldcreate">'.$langs->trans(
"DefaultContact").
'</td><td class="valuefieldcreate">';
1708 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1,
'',
'', 0,
'minwidth300');
1712 print
'<tr class="field_discount_info"><td class="titlefieldcreate">'.$langs->trans(
'Discounts').
'</td><td class="valuefieldcreate">';
1714 $absolute_discount = $soc->getAvailableDiscounts();
1718 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1719 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1724 print
'<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'DatePropal').
'</td><td class="valuefieldcreate">';
1725 print
$form->selectDate(
'',
'',
'',
'',
'',
"addprop", 1, 1);
1729 print
'<tr class="field_duree_validitee"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"ValidityDuration").
'</td><td class="valuefieldcreate">'.
img_picto(
'',
'clock',
'class="paddingright"').
'<input name="duree_validite" class="width50" value="'.(
GETPOSTISSET(
'duree_validite') ?
GETPOST(
'duree_validite',
'alphanohtml') : $conf->global->PROPALE_VALIDITY_DURATION).
'"> '.$langs->trans(
"days").
'</td></tr>';
1732 print
'<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1734 $form->select_conditions_paiements((
GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id',
'int') != 0) ?
GETPOST(
'cond_reglement_id',
'int') : $soc->cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'', (
GETPOSTISSET(
'cond_reglement_id_deposit_percent') ?
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha') : $soc->deposit_percent));
1738 print
'<tr class="field_mode_reglement_id"><td class="titlefieldcreate">'.$langs->trans(
'PaymentMode').
'</td><td class="valuefieldcreate">';
1739 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1740 $form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOST(
'mode_reglement_id',
'int') != 0) ?
GETPOST(
'mode_reglement_id',
'int') : $soc->mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
1744 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
1745 print
'<tr class="field_fk_account"><td class="titlefieldcreate">'.$langs->trans(
'BankAccount').
'</td><td class="valuefieldcreate">';
1746 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($soc->fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1751 print
'<tr class="field_demand_reason_id"><td class="titlefieldcreate">'.$langs->trans(
'Source').
'</td><td class="valuefieldcreate">';
1752 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1753 $form->selectInputReason(
'',
'demand_reason_id',
"SRC_PROP", 1,
'maxwidth200 widthcentpercentminusx');
1757 print
'<tr class="field_availability_id"><td class="titlefieldcreate">'.$langs->trans(
'AvailabilityPeriod');
1758 if (!empty($conf->commande->enabled)) {
1759 print
' ('.$langs->trans(
'AfterOrder').
')';
1761 print
'</td><td class="valuefieldcreate">';
1762 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1763 $form->selectAvailabilityDelay(
'',
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1767 if (!empty($conf->expedition->enabled)) {
1768 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1769 $shipping_method_id = $soc->shipping_method_id;
1771 print
'<tr class="field_shipping_method_id"><td class="titlefieldcreate">'.$langs->trans(
'SendingMethod').
'</td><td class="valuefieldcreate">';
1772 print
img_picto(
'',
'object_dollyrevert',
'class="pictofixedwidth"');
1773 print
$form->selectShippingMethod($shipping_method_id,
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1778 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1779 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1781 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">'.$langs->trans(
'Warehouse').
'</td><td class="valuefieldcreate">';
1782 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id,
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1787 print
'<tr class="field_date_livraison"><td class="titlefieldcreate">'.$langs->trans(
"DeliveryDate").
'</td>';
1788 print
'<td class="valuefieldcreate">';
1789 if (isset($conf->global->DATE_LIVRAISON_WEEK_DELAY) && is_numeric($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
1790 $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1791 $syear = date(
"Y", $tmpdte);
1792 $smonth = date(
"m", $tmpdte);
1793 $sday = date(
"d", $tmpdte);
1794 print
$form->selectDate($syear.
"-".$smonth.
"-".$sday,
'date_livraison',
'',
'',
'',
"addprop");
1796 print
$form->selectDate(-1,
'date_livraison',
'',
'',
'',
"addprop", 1, 1);
1801 if (!empty($conf->project->enabled)) {
1802 $langs->load(
"projects");
1803 print
'<tr class="field_projectid">';
1804 print
'<td class="titlefieldcreate">'.$langs->trans(
"Project").
'</td><td class="valuefieldcreate">';
1805 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
1806 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.$soc->id.
'&action=create&status=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create&socid='.$soc->id).
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddProject").
'"></span></a>';
1812 if (!empty($conf->incoterm->enabled)) {
1813 print
'<tr class="field_incoterm_id">';
1814 print
'<td class="titlefieldcreate"><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $soc->label_incoterms, 1).
'</label></td>';
1815 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1816 print
$form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms :
''), (!empty($soc->location_incoterms) ? $soc->location_incoterms :
''));
1821 print
'<tr class="field_model">';
1822 print
'<td class="titlefieldcreate">'.$langs->trans(
"DefaultModel").
'</td>';
1823 print
'<td class="valuefieldcreate">';
1824 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1826 $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT :
getDolGlobalString(
"PROPALE_ADDON_PDF"));
1827 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1831 if (!empty($conf->multicurrency->enabled)) {
1832 print
'<tr class="field_currency">';
1833 print
'<td class="titlefieldcreate">'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1834 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1835 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code,
'multicurrency_code', 0);
1840 print
'<tr class="field_note_public">';
1841 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1842 print
'<td class="valuefieldcreate">';
1843 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc) ? $objectsrc->note_public :
null));
1844 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
1845 print $doleditor->Create(1);
1848 if (empty($user->socid)) {
1849 print
'<tr class="field_note_private">';
1850 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1851 print
'<td class="valuefieldcreate">';
1852 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private :
null));
1853 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
1854 print $doleditor->Create(1);
1860 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
1863 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1865 if ($origin ==
'contrat') {
1867 $objectsrc->remise_absolue = $remise_absolue;
1868 $objectsrc->remise_percent = $remise_percent;
1869 $objectsrc->update_price(1, - 1, 1);
1872 print
"\n<!-- ".$classname.
" info -->";
1874 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1875 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1876 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1877 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1878 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1880 $newclassname = $classname;
1881 if ($newclassname ==
'Propal') {
1882 $newclassname =
'CommercialProposal';
1883 } elseif ($newclassname ==
'Commande') {
1884 $newclassname =
'Order';
1885 } elseif ($newclassname ==
'Expedition') {
1886 $newclassname =
'Sending';
1887 } elseif ($newclassname ==
'Fichinter') {
1888 $newclassname =
'Intervention';
1891 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
1892 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).
'</td></tr>';
1893 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1894 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1895 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1898 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1899 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1901 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1903 if (!empty($conf->multicurrency->enabled)) {
1904 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1905 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
1906 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
1917 if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
1918 print
'<input type="hidden" name="createmode" value="empty">';
1921 if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
1922 print
'<br><table>';
1926 print
'<td><input type="radio" name="createmode" value="copy"></td>';
1927 print
'<td>'.$langs->trans(
"CopyPropalFrom").
' </td>';
1929 $liste_propal = array();
1930 $liste_propal [0] =
'';
1932 $sql =
"SELECT p.rowid as id, p.ref, s.nom";
1933 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal p";
1934 $sql .=
", ".MAIN_DB_PREFIX.
"societe s";
1935 $sql .=
" WHERE s.rowid = p.fk_soc";
1936 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
1937 $sql .=
" AND p.fk_statut <> 0";
1938 $sql .=
" ORDER BY Id";
1940 $resql = $db->query($sql);
1942 $num = $db->num_rows(
$resql);
1945 $row = $db->fetch_row(
$resql);
1946 $propalRefAndSocName = $row [1].
" - ".$row [2];
1947 $liste_propal [$row [0]] = $propalRefAndSocName;
1950 print
$form->selectarray(
"copie_propal", $liste_propal, 0);
1956 print
'<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1957 print
'<td valign="top" colspan="2">'.$langs->trans(
"CreateEmptyPropal").
'</td></tr>';
1963 $langs->load(
"bills");
1965 print
$form->buttonsSaveCancel(
"CreateDraft");
1971 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1974 $title = $langs->trans(
'ProductsAndServices');
1977 print
'<div class="div-table-responsive-no-min">';
1978 print
'<table class="noborder centpercent">';
1980 $objectsrc->printOriginLinesList();
1985 } elseif ($object->id > 0) {
1991 $soc->fetch($object->socid);
1999 if ($action ==
'clone') {
2001 $formquestion = array(
2004 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.client=1 OR s.client=2 OR s.client=3)',
'', 0, 0,
null, 0,
'maxwidth300')),
2005 array(
'type' =>
'checkbox',
'name' =>
'update_prices',
'label' => $langs->trans(
'PuttingPricesUpToDate'),
'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
2007 if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
2008 $formquestion[] = array(
'type' =>
'date',
'name' =>
'date_delivery',
'label' => $langs->trans(
"DeliveryDate"),
'value' => $object->delivery_date);
2011 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmClonePropal', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2014 if ($action ==
'closeas') {
2016 $formquestion = array(
2017 array(
'type' =>
'select',
'name' =>
'statut',
'label' =>
'<span class="fieldrequired">'.$langs->trans(
"CloseAs").
'</span>',
'values' => array($object::STATUS_SIGNED => $object->LibStatut($object::STATUS_SIGNED), $object::STATUS_NOTSIGNED => $object->LibStatut($object::STATUS_NOTSIGNED))),
2018 array(
'type' =>
'text',
'name' =>
'note_private',
'label' => $langs->trans(
"Note"),
'value' =>
'')
2021 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2023 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && ! empty($user->rights->facture->creer)) {
2024 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2026 $object->fetchObjectLinked();
2028 $eligibleForDepositGeneration =
true;
2030 if (array_key_exists(
'facture', $object->linkedObjects)) {
2031 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2033 $eligibleForDepositGeneration =
false;
2039 if ($eligibleForDepositGeneration && array_key_exists(
'commande', $object->linkedObjects)) {
2040 foreach ($object->linkedObjects[
'commande'] as $order) {
2041 $order->fetchObjectLinked();
2043 if (array_key_exists(
'facture', $order->linkedObjects)) {
2044 foreach ($order->linkedObjects[
'facture'] as $invoice) {
2046 $eligibleForDepositGeneration =
false;
2055 if ($eligibleForDepositGeneration) {
2056 $formquestion[] = array(
2057 'type' =>
'checkbox',
2058 'tdclass' =>
'showonlyifsigned',
2059 'name' =>
'generate_deposit',
2060 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2063 $formquestion[] = array(
2065 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2067 'label' => $langs->trans(
'DateInvoice'),
2072 if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2073 $formquestion[] = array(
2075 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2076 'name' =>
'date_pointoftax',
2077 'label' => $langs->trans(
'DatePointOfTax'),
2084 $form->select_conditions_paiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2085 $paymentTermsSelect = ob_get_clean();
2087 $formquestion[] = array(
2089 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2090 'name' =>
'cond_reglement_id',
2091 'label' => $langs->trans(
'PaymentTerm'),
2092 'value' => $paymentTermsSelect
2095 $formquestion[] = array(
2096 'type' =>
'checkbox',
2097 'tdclass' =>
'showonlyifgeneratedeposit',
2098 'name' =>
'validate_generated_deposit',
2099 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2102 $formquestion[] = array(
2103 'type' =>
'onecolumn',
2106 let signedValue = ' . $object::STATUS_SIGNED .
';
2108 $(document).ready(function() {
2109 $("[name=generate_deposit]").change(function () {
2110 let $self = $(this);
2111 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2113 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2122 $("#statut").change(function() {
2123 let $target = $(".showonlyifsigned").parent(".tagtr");
2125 if ($(this).val() == signedValue) {
2131 $("[name=generate_deposit]").trigger("change");
2136 $("#statut").trigger("change");
2144 if (!empty($conf->notification->enabled)) {
2145 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2146 $notify =
new Notify($db);
2147 $formquestion = array_merge($formquestion, array(
2148 array(
'type' =>
'onecolumn',
'value' => $notify->confirmMessage(
'PROPAL_CLOSE_SIGNED', $object->socid, $object)),
2152 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'SetAcceptedRefused'), $text,
'confirm_closeas', $formquestion,
'', 1, 250);
2153 } elseif ($action ==
'delete') {
2155 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteProp'), $langs->trans(
'ConfirmDeleteProp', $object->ref),
'confirm_delete',
'', 0, 1);
2156 } elseif ($action ==
'reopen') {
2158 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ReOpen'), $langs->trans(
'ConfirmReOpenProp', $object->ref),
'confirm_reopen',
'', 0, 1);
2159 } elseif ($action ==
'ask_deleteline') {
2161 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2162 } elseif ($action ==
'validate') {
2167 $ref = substr($object->ref, 1, 4);
2168 if ($ref ==
'PROV' || $ref ==
'') {
2169 $numref = $object->getNextNumRef($soc);
2170 if (empty($numref)) {
2175 $numref = $object->ref;
2178 $text = $langs->trans(
'ConfirmValidateProp', $numref);
2179 if (!empty($conf->notification->enabled)) {
2180 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2181 $notify =
new Notify($db);
2183 $text .= $notify->confirmMessage(
'PROPAL_VALIDATE', $object->socid, $object);
2188 foreach ($object->lines as $line) {
2189 $res = $line->fetch_product();
2191 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2197 if ($nbMandated > 0) {
2198 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2202 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateProp'), $text,
'confirm_validate',
'', 0, 1);
2208 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2209 if (empty($reshook)) {
2211 } elseif ($reshook > 0) {
2221 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2223 $morehtmlref =
'<div class="refidno">';
2225 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2226 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2228 $morehtmlref .=
'<br><span class="hideonsmartphone">'.$langs->trans(
'ThirdParty').
' : </span>'.$object->thirdparty->getNomUrl(1,
'customer');
2229 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2230 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherProposals").
'</a>)';
2233 if (!empty($conf->project->enabled)) {
2234 $langs->load(
"projects");
2235 $morehtmlref .=
'<br><span class="paddingrightonly">'.$langs->trans(
'Project').
'</span>';
2236 if ($usercancreate) {
2237 if ($action !=
'classify') {
2238 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2240 if ($action ==
'classify') {
2242 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2243 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2244 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2245 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
2246 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2247 $morehtmlref .=
'</form>';
2249 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2252 if (!empty($object->fk_project)) {
2254 $proj->fetch($object->fk_project);
2255 $morehtmlref .=
': '.$proj->getNomUrl(1);
2257 $morehtmlref .=
' - '.$proj->title;
2264 $morehtmlref .=
'</div>';
2267 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2270 print
'<div class="fichecenter">';
2271 print
'<div class="fichehalfleft">';
2272 print
'<div class="underbanner clearboth"></div>';
2274 print
'<table class="border tableforfield" width="100%">';
2277 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2278 $filterabsolutediscount =
"fk_facture_source IS NULL";
2279 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2281 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2282 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2285 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2287 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2288 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2289 $absolute_discount =
price2num($absolute_discount,
'MT');
2290 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2296 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2297 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2313 print
$form->editfieldkey(
"DatePropal",
'date',
'', $object, $editenable);
2314 print
'</td><td class="valuefield">';
2315 if ($action ==
'editdate' && $usercancreate && $caneditfield) {
2316 print
'<form name="editdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2317 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2318 print
'<input type="hidden" name="action" value="setdate">';
2319 print
$form->selectDate($object->date,
're',
'',
'', 0,
"editdate");
2320 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2323 if ($object->date) {
2334 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2335 print $langs->trans(
'DateEndPropal');
2337 if ($action !=
'editecheance' && $usercancreate && $caneditfield) {
2338 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editecheance&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
2340 print
'</tr></table>';
2341 print
'</td><td class="valuefield">';
2342 if ($action ==
'editecheance' && $usercancreate && $caneditfield) {
2343 print
'<form name="editecheance" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2344 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2345 print
'<input type="hidden" name="action" value="setecheance">';
2346 print
$form->selectDate($object->fin_validite,
'ech',
'',
'',
'',
"editecheance");
2347 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2350 if (!empty($object->fin_validite)) {
2352 if ($object->statut ==
Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) {
2364 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2365 print $langs->trans(
'PaymentConditionsShort');
2367 if ($action !=
'editconditions' && $usercancreate && $caneditfield) {
2368 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetConditions'), 1).
'</a></td>';
2370 print
'</tr></table>';
2371 print
'</td><td class="valuefield">';
2372 if ($action ==
'editconditions' && $usercancreate && $caneditfield) {
2373 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 0,
'', 1, $object->deposit_percent);
2375 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 0,
'', 1, $object->deposit_percent);
2381 print
'<tr class="field_mode_reglement_id">';
2382 print
'<td class="titlefieldcreate">';
2383 print
'<table class="nobordernopadding centpercent"><tr><td>';
2384 print $langs->trans(
'PaymentMode');
2386 if ($action !=
'editmode' && $usercancreate && $caneditfield) {
2387 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMode'), 1).
'</a></td>';
2389 print
'</tr></table>';
2390 print
'</td><td class="valuefieldcreate">';
2391 if ($action ==
'editmode' && $usercancreate && $caneditfield) {
2392 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2394 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2399 $langs->load(
'deliveries');
2401 print
$form->editfieldkey($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2402 print
'</td><td class="valuefieldedit">';
2403 print
$form->editfieldval($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2408 print
'<tr class="fielddeliverydelay"><td>';
2409 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2410 if (!empty($conf->commande->enabled)) {
2411 print
$form->textwithpicto($langs->trans(
'AvailabilityPeriod'), $langs->trans(
'AvailabilityPeriod').
' ('.$langs->trans(
'AfterOrder').
')');
2413 print $langs->trans(
'AvailabilityPeriod');
2416 if ($action !=
'editavailability' && $usercancreate && $caneditfield) {
2417 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editavailability&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetAvailability'), 1).
'</a></td>';
2419 print
'</tr></table>';
2420 print
'</td><td class="valuefield">';
2421 if ($action ==
'editavailability' && $usercancreate && $caneditfield) {
2422 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2424 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2431 if (!empty($conf->expedition->enabled)) {
2433 print
'<table class="nobordernopadding centpercent"><tr><td>';
2434 print $langs->trans(
'SendingMethod');
2436 if ($action !=
'editshippingmethod' && $usercancreate && $caneditfield) {
2437 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editshippingmethod&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetShippingMode'), 1).
'</a></td>';
2439 print
'</tr></table>';
2440 print
'</td><td class="valuefield">';
2441 if ($action ==
'editshippingmethod' && $usercancreate && $caneditfield) {
2442 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2444 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2451 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
2452 $langs->load(
'stocks');
2453 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2455 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">';
2456 $editenable = $usercancreate;
2457 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2458 print
'</td><td class="valuefieldcreate">';
2459 if ($action ==
'editwarehouse') {
2460 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2462 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2470 print
'<table class="nobordernopadding centpercent"><tr><td>';
2471 print $langs->trans(
'Source');
2473 if ($action !=
'editdemandreason' && $usercancreate) {
2474 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdemandreason&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetDemandReason'), 1).
'</a></td>';
2476 print
'</tr></table>';
2477 print
'</td><td class="valuefield">';
2478 if ($action ==
'editdemandreason' && $usercancreate) {
2479 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2481 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2487 if (!empty($conf->multicurrency->enabled)) {
2491 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2492 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2494 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) {
2495 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2497 print
'</tr></table>';
2498 print
'</td><td class="valuefield">';
2499 if ($object->statut == $object::STATUS_DRAFT && $action ==
'editmulticurrencycode' && $usercancreate) {
2500 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2502 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2507 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2510 print
'<table class="nobordernopadding" width="100%"><tr>';
2512 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2514 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) {
2515 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2517 print
'</tr></table>';
2518 print
'</td><td class="valuefield">';
2519 if ($object->statut == $object::STATUS_DRAFT && ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') && $usercancreate) {
2520 if ($action ==
'actualizemulticurrencyrate') {
2523 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2525 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2526 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2527 print
'<div class="inline-block"> ';
2528 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2536 if ($soc->outstanding_limit) {
2539 print $langs->trans(
'OutstandingBill');
2540 print
'</td><td class="valuefield">';
2541 $arrayoutstandingbills = $soc->getOutstandingBills();
2542 print ($arrayoutstandingbills[
'opened'] > $soc->outstanding_limit ?
img_warning() :
'');
2543 print
price($arrayoutstandingbills[
'opened']).
' / ';
2544 print
price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
2549 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
2552 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2553 print $langs->trans(
'BankAccount');
2555 if ($action !=
'editbankaccount' && $usercancreate) {
2556 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
2558 print
'</tr></table>';
2559 print
'</td><td class="valuefield">';
2560 if ($action ==
'editbankaccount') {
2561 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2563 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2569 $tmparray = $object->getTotalWeightVolume();
2570 $totalWeight = $tmparray[
'weight'];
2571 $totalVolume = $tmparray[
'volume'];
2573 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2574 print
'<td class="valuefield">';
2575 print
showDimensionInBestUnit($totalWeight, 0,
"weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT :
'no', 0);
2579 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2580 print
'<td class="valuefield">';
2581 print
showDimensionInBestUnit($totalVolume, 0,
"volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT :
'no', 0);
2586 if (!empty($conf->incoterm->enabled)) {
2588 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2589 print $langs->trans(
'IncotermLabel');
2590 print
'<td><td class="right">';
2591 if ($action !=
'editincoterm' && $usercancreate && $caneditfield) {
2592 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/comm/propal/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2596 print
'</td></tr></table>';
2598 print
'<td class="valuefield">';
2599 if ($action ==
'editincoterm' && $usercancreate && $caneditfield) {
2600 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2602 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2608 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2613 print
'<div class="fichehalfright">';
2614 print
'<div class="underbanner clearboth"></div>';
2616 print
'<table class="border tableforfield centpercent">';
2618 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2620 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2621 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2625 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2626 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2630 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2631 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2636 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2637 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2641 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
2642 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2646 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2647 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2648 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2651 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2652 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2653 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2658 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
2659 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2668 if (!empty($conf->margin->enabled)) {
2669 $formmargin->displayMarginInfos($object);
2675 print
'<div class="clearboth"></div><br>';
2677 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2678 $blocname =
'contacts';
2679 $title = $langs->trans(
'ContactsAddresses');
2680 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2683 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2684 $blocname =
'notes';
2685 $title = $langs->trans(
'Notes');
2686 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2694 $result = $object->getLinesArray();
2696 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2697 <input type="hidden" name="token" value="' .
newToken().
'">
2698 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2699 <input type="hidden" name="mode" value="">
2700 <input type="hidden" name="page_y" value="">
2701 <input type="hidden" name="id" value="' . $object->id.
'">
2705 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2708 print
'<div class="div-table-responsive-no-min">';
2709 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2710 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2713 if (!empty($object->lines)) {
2714 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2719 if ($action !=
'editline') {
2723 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2724 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2725 if (empty($reshook))
2726 $object->formAddObjectLine(1, $mysoc, $soc);
2729 $reshook = $hookmanager->executeHooks(
'formEditObjectLine',
$parameters, $object, $action);
2733 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2747 if ($action !=
'presend') {
2748 print
'<div class="tabsAction">';
2751 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2753 if (empty($reshook)) {
2754 if ($action !=
'editline') {
2756 if (($object->statut ==
Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
2757 || ($object->statut ==
Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
2758 if ($usercanvalidate) {
2759 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=validate&token='.
newToken().
'">'.$langs->trans(
'Validate').
'</a>';
2761 print
'<a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
'Validate').
'</a>';
2771 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=modif&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
2776 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#reopen').
'"';
2777 print
'>'.$langs->trans(
'ReOpen').
'</a>';
2781 if (empty($user->socid)) {
2784 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2786 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'SendMail').
'</a>';
2793 if ($usercancreateorder) {
2794 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid.
'">'.$langs->trans(
"AddOrder").
'</a>';
2799 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
2800 if ($object->statut ==
Propal::STATUS_SIGNED && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled))) {
2801 if ($usercancreatepurchaseorder) {
2802 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid.
'">'.$langs->trans(
"AddPurchaseOrder").
'</a>';
2808 if (!empty($conf->service->enabled) && !empty($conf->ficheinter->enabled) && $object->statut ==
Propal::STATUS_SIGNED) {
2809 if ($usercancreateintervention) {
2810 $langs->load(
"interventions");
2811 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid.
'">'.$langs->trans(
"AddIntervention").
'</a>';
2817 $langs->load(
"contracts");
2819 if ($usercancreatecontract) {
2820 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid.
'">'.$langs->trans(
'AddContract').
'</a>';
2826 if (
isModEnabled(
'facture') && $usercancreateinvoice) {
2827 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid.
'">'.$langs->trans(
"CreateBill").
'</a>';
2830 $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
2831 if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
2832 if ($usercanclose) {
2833 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'&socid='.$object->socid.
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2835 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2842 if ($usercanclose) {
2843 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=closeas&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#close').
'"';
2844 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2846 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'"';
2847 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2852 if ($usercancreate) {
2853 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&token='.
newToken().
'&object='.$object->element.
'">'.$langs->trans(
"ToClone").
'</a>';
2857 if ($usercandelete) {
2858 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'"';
2859 print
'>'.$langs->trans(
'Delete').
'</a>';
2868 if (
GETPOST(
'modelselected')) {
2869 $action =
'presend';
2872 if ($action !=
'presend') {
2873 print
'<div class="fichecenter"><div class="fichehalfleft">';
2874 print
'<a name="builddoc"></a>';
2879 $filedir = $conf->propal->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2880 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2881 $genallowed = $usercanread;
2882 $delallowed = $usercancreate;
2884 print $formfile->showdocuments(
'propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'', 0,
'', $soc->default_lang,
'', $object);
2887 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'propal'));
2889 $compatibleImportElementsList =
false;
2891 $compatibleImportElementsList = array(
'commande',
'propal');
2893 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2896 $useonlinesignature = 1;
2899 print
'<br><!-- Link to sign -->';
2900 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2901 print showOnlineSignatureUrl(
'proposal', $object->ref).
'<br>';
2904 print
'</div><div class="fichehalfright">';
2907 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2909 $somethingshown =
$formactions->showactions($object,
'propal', $socid, 1);
2911 print
'</div></div>';
2915 $modelmail =
'propal_send';
2916 $defaulttopic =
'SendPropalRef';
2917 $diroutput = $conf->propal->multidir_output[$object->entity];
2918 $trackid =
'pro'.$object->id;
2920 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';