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 $propal_qty_requirement = (!empty($conf->global->PROPAL_ENABLE_NEGATIVE_QTY) ? ($qty >= 0 || $qty <= 0) : $qty >= 0);
975 if (!$error && $propal_qty_requirement && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
979 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
989 if (!empty($idprod) && $idprod > 0) {
991 $prod->fetch($idprod);
993 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
998 if (empty($tva_tx)) {
1003 $pu_ht = $prod->price;
1004 $pu_ttc = $prod->price_ttc;
1005 $price_min = $prod->price_min;
1006 $price_base_type = $prod->price_base_type;
1009 if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
1010 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
1011 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
1012 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
1013 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
1014 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1015 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
1016 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
1018 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
1019 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
1022 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1024 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
1028 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
1030 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
1033 if (count($prodcustprice->lines) > 0) {
1034 $pu_ht =
price($prodcustprice->lines[0]->price);
1035 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
1036 $price_min =
price($prodcustprice->lines[0]->price_min);
1037 $price_base_type = $prodcustprice->lines[0]->price_base_type;
1038 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1039 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1040 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1042 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1043 if (empty($tva_tx)) {
1048 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
1050 if ($prod->prices_by_qty[0]) {
1055 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
1056 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1060 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1061 $pu_ht = $priceforthequantityarray[
'unitprice'];
1063 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1069 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1071 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
1076 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
1077 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1081 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1082 $pu_ht = $priceforthequantityarray[
'unitprice'];
1084 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1092 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
1093 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
1096 if (!empty($price_ht) || $price_ht ===
'0') {
1098 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1099 } elseif ($tmpvat != $tmpprodvat) {
1102 if ($price_base_type !=
'HT') {
1103 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1105 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1112 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1113 $outputlangs = $langs;
1115 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1116 $newlang =
GETPOST(
'lang_id',
'aZ09');
1118 if (empty($newlang)) {
1119 $newlang = $object->thirdparty->default_lang;
1121 if (!empty($newlang)) {
1122 $outputlangs =
new Translate(
"", $conf);
1123 $outputlangs->setDefaultLang($newlang);
1126 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
1128 $desc = $prod->description;
1132 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1136 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1137 $desc = $product_desc;
1139 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1155 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
1158 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1159 $outputlangs = $langs;
1161 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
1162 $newlang =
GETPOST(
'lang_id',
'alpha');
1164 if (empty($newlang)) {
1165 $newlang = $object->thirdparty->default_lang;
1167 if (!empty($newlang)) {
1168 $outputlangs =
new Translate(
"", $conf);
1169 $outputlangs->setDefaultLang($newlang);
1170 $outputlangs->load(
'products');
1172 if (!empty($prod->customcode)) {
1173 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1175 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1178 if (!empty($prod->country_code)) {
1179 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
1182 if (!empty($prod->customcode)) {
1183 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1185 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1188 if (!empty($prod->country_code)) {
1189 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
1196 $type = $prod->type;
1197 $fk_unit = $prod->fk_unit;
1201 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1202 $tva_tx = str_replace(
'*',
'', $tva_tx);
1203 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1204 $desc = $product_desc;
1207 $fk_unit =
GETPOST(
'units',
'alpha');
1208 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1219 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
1220 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
1227 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)))) {
1228 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
1232 $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);
1237 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1239 $outputlangs = $langs;
1240 if (!empty($conf->global->MAIN_MULTILANGS)) {
1241 $outputlangs =
new Translate(
"", $conf);
1242 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1243 $outputlangs->setDefaultLang($newlang);
1245 $ret = $object->fetch($id);
1247 $object->fetch_thirdparty();
1249 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1252 unset($_POST[
'prod_entry_mode']);
1254 unset($_POST[
'qty']);
1255 unset($_POST[
'type']);
1256 unset($_POST[
'remise_percent']);
1257 unset($_POST[
'price_ht']);
1258 unset($_POST[
'multicurrency_price_ht']);
1259 unset($_POST[
'price_ttc']);
1260 unset($_POST[
'tva_tx']);
1261 unset($_POST[
'product_ref']);
1262 unset($_POST[
'product_label']);
1263 unset($_POST[
'product_desc']);
1264 unset($_POST[
'fournprice']);
1265 unset($_POST[
'buying_price']);
1266 unset($_POST[
'np_marginRate']);
1267 unset($_POST[
'np_markRate']);
1268 unset($_POST[
'dp_desc']);
1269 unset($_POST[
'idprod']);
1270 unset($_POST[
'units']);
1272 unset($_POST[
'date_starthour']);
1273 unset($_POST[
'date_startmin']);
1274 unset($_POST[
'date_startsec']);
1275 unset($_POST[
'date_startday']);
1276 unset($_POST[
'date_startmonth']);
1277 unset($_POST[
'date_startyear']);
1278 unset($_POST[
'date_endhour']);
1279 unset($_POST[
'date_endmin']);
1280 unset($_POST[
'date_endsec']);
1281 unset($_POST[
'date_endday']);
1282 unset($_POST[
'date_endmonth']);
1283 unset($_POST[
'date_endyear']);
1291 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1295 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1304 $vat_rate = str_replace(
'*',
'', $vat_rate);
1305 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1306 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1321 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1322 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1324 if (is_array($extralabelsline)) {
1326 foreach ($extralabelsline as $key => $value) {
1327 unset($_POST[
"options_".$key]);
1332 $special_code =
GETPOST(
'special_code',
'int');
1338 $productid =
GETPOST(
'productid',
'int');
1339 if (!empty($productid)) {
1341 $res = $product->fetch($productid);
1343 $type = $product->type;
1345 $price_min = $product->price_min;
1346 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1347 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
1351 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)))) {
1352 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
1357 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1361 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1369 if (empty($user->rights->margins->creer)) {
1370 foreach ($object->lines as &$line) {
1371 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1372 $fournprice = $line->fk_fournprice;
1373 $buyingprice = $line->pa_ht;
1381 $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);
1386 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1388 $outputlangs = $langs;
1389 if (!empty($conf->global->MAIN_MULTILANGS)) {
1390 $outputlangs =
new Translate(
"", $conf);
1391 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1392 $outputlangs->setDefaultLang($newlang);
1394 $ret = $object->fetch($id);
1396 $object->fetch_thirdparty();
1398 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1401 unset($_POST[
'qty']);
1402 unset($_POST[
'type']);
1403 unset($_POST[
'productid']);
1404 unset($_POST[
'remise_percent']);
1405 unset($_POST[
'price_ht']);
1406 unset($_POST[
'multicurrency_price_ht']);
1407 unset($_POST[
'price_ttc']);
1408 unset($_POST[
'tva_tx']);
1409 unset($_POST[
'product_ref']);
1410 unset($_POST[
'product_label']);
1411 unset($_POST[
'product_desc']);
1412 unset($_POST[
'fournprice']);
1413 unset($_POST[
'buying_price']);
1415 unset($_POST[
'date_starthour']);
1416 unset($_POST[
'date_startmin']);
1417 unset($_POST[
'date_startsec']);
1418 unset($_POST[
'date_startday']);
1419 unset($_POST[
'date_startmonth']);
1420 unset($_POST[
'date_startyear']);
1421 unset($_POST[
'date_endhour']);
1422 unset($_POST[
'date_endmin']);
1423 unset($_POST[
'date_endsec']);
1424 unset($_POST[
'date_endday']);
1425 unset($_POST[
'date_endmonth']);
1426 unset($_POST[
'date_endyear']);
1433 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1434 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1436 } elseif ($action ==
'classin' && $usercancreate) {
1438 $object->setProject(
GETPOST(
'projectid',
'int'));
1439 } elseif ($action ==
'setavailability' && $usercancreate) {
1441 $result = $object->set_availability($user,
GETPOST(
'availability_id',
'int'));
1442 } elseif ($action ==
'setdemandreason' && $usercancreate) {
1444 $result = $object->set_demand_reason($user,
GETPOST(
'demand_reason_id',
'int'));
1445 } elseif ($action ==
'setconditions' && $usercancreate) {
1447 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
1448 } elseif ($action ==
'setremisepercent' && $usercancreate) {
1449 $result = $object->set_remise_percent($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
1450 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
1451 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
1452 } elseif ($action ==
'setmode' && $usercancreate) {
1454 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
1455 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
1457 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
1458 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
1460 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
1461 } elseif ($action ==
'setbankaccount' && $usercancreate) {
1463 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
1464 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
1466 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
1467 } elseif ($action ==
'setwarehouse' && $usercancreate) {
1469 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
1470 } elseif ($action ==
'update_extras') {
1471 $object->oldcopy =
dol_clone($object, 2);
1474 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1479 $result = $object->insertExtraFields(
'PROPAL_MODIFY');
1486 $action =
'edit_extras';
1490 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1491 if ($action ==
'addcontact') {
1492 if ($object->id > 0) {
1495 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1499 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1502 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1503 $langs->load(
"errors");
1504 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1509 } elseif ($action ==
'swapstatut') {
1511 if ($object->fetch($id) > 0) {
1512 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1516 } elseif ($action ==
'deletecontact') {
1518 $object->fetch($id);
1519 $result = $object->delete_contact($lineid);
1522 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1531 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
1532 $permissiontoadd = $usercancreate;
1533 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1545 if (!empty($conf->project->enabled)) {
1549 $title = $langs->trans(
'Proposal').
" - ".$langs->trans(
'Card');
1550 $help_url =
'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
1556 if ($action ==
'create') {
1557 $currency_code = $conf->currency;
1563 $res = $soc->fetch($socid);
1567 if (!empty($origin) && !empty($originid)) {
1569 $element = $subelement = $origin;
1571 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1572 $element = $regs[1];
1573 $subelement = $regs[2];
1576 if ($element ==
'project') {
1577 $projectid = $originid;
1580 if ($element ==
'order' || $element ==
'commande') {
1581 $element = $subelement =
'commande';
1583 if ($element ==
'propal') {
1584 $element =
'comm/propal';
1585 $subelement =
'propal';
1587 if ($element ==
'contract') {
1588 $element = $subelement =
'contrat';
1590 if ($element ==
'shipping') {
1591 $element = $subelement =
'expedition';
1596 $classname = ucfirst($subelement);
1597 $objectsrc =
new $classname($db);
1598 $objectsrc->fetch($originid);
1599 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1600 $objectsrc->fetch_lines();
1602 $objectsrc->fetch_thirdparty();
1604 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
1605 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1607 $soc = $objectsrc->thirdparty;
1609 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1610 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1611 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1612 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1613 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1614 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
1617 $objectsrc->fetch_optionals();
1618 $object->array_options = $objectsrc->array_options;
1620 if (!empty($conf->multicurrency->enabled)) {
1621 if (!empty($objectsrc->multicurrency_code)) {
1622 $currency_code = $objectsrc->multicurrency_code;
1624 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1625 $currency_tx = $objectsrc->multicurrency_tx;
1630 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1631 $currency_code = $soc->multicurrency_code;
1636 if ($soc->fk_warehouse > 0) {
1637 $warehouse_id = $soc->fk_warehouse;
1639 if (!empty($conf->stock->enabled) && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1640 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1641 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1643 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1644 $warehouse_id = $user->fk_warehouse;
1648 print
'<form name="addprop" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1649 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1650 print
'<input type="hidden" name="action" value="add">';
1651 if ($origin !=
'project' && $originid) {
1652 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1653 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1654 } elseif ($origin ==
'project' && !empty($projectid)) {
1655 print
'<input type="hidden" name="projectid" value="'.$projectid.
'">';
1660 print
'<table class="border centpercent">';
1663 print
'<tr class="field_ref"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td class="valuefieldcreate">'.$langs->trans(
"Draft").
'</td></tr>';
1666 print
'<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans(
'RefCustomer').
'</td><td class="valuefieldcreate">';
1667 print
'<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:
GETPOST(
'ref_client')).
'"></td>';
1671 print
'<tr class="field_socid">';
1672 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1673 $shipping_method_id = 0;
1675 print
'<td class="valuefieldcreate">';
1676 print $soc->getNomUrl(1,
'customer');
1677 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1679 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1680 $shipping_method_id = $soc->shipping_method_id;
1684 print
'<td class="valuefieldcreate">';
1685 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');
1687 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1688 print
'<script type="text/javascript">
1689 $(document).ready(function() {
1690 $("#socid").change(function() {
1691 console.log("We have changed the company - Reload page");
1692 var socid = $(this).val();
1694 $("input[name=action]").val("create");
1695 $("form[name=addprop]").submit();
1700 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>';
1707 print
'<tr class="field_contactid"><td class="titlefieldcreate">'.$langs->trans(
"DefaultContact").
'</td><td class="valuefieldcreate">';
1709 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1,
'',
'', 0,
'minwidth300');
1713 print
'<tr class="field_discount_info"><td class="titlefieldcreate">'.$langs->trans(
'Discounts').
'</td><td class="valuefieldcreate">';
1715 $absolute_discount = $soc->getAvailableDiscounts();
1719 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1720 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1725 print
'<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'DatePropal').
'</td><td class="valuefieldcreate">';
1726 print
$form->selectDate(
'',
'',
'',
'',
'',
"addprop", 1, 1);
1730 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>';
1733 print
'<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1735 $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));
1739 print
'<tr class="field_mode_reglement_id"><td class="titlefieldcreate">'.$langs->trans(
'PaymentMode').
'</td><td class="valuefieldcreate">';
1740 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1741 $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');
1745 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
1746 print
'<tr class="field_fk_account"><td class="titlefieldcreate">'.$langs->trans(
'BankAccount').
'</td><td class="valuefieldcreate">';
1747 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($soc->fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1752 print
'<tr class="field_demand_reason_id"><td class="titlefieldcreate">'.$langs->trans(
'Source').
'</td><td class="valuefieldcreate">';
1753 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1754 $form->selectInputReason(
'',
'demand_reason_id',
"SRC_PROP", 1,
'maxwidth200 widthcentpercentminusx');
1758 print
'<tr class="field_availability_id"><td class="titlefieldcreate">'.$langs->trans(
'AvailabilityPeriod');
1759 if (!empty($conf->commande->enabled)) {
1760 print
' ('.$langs->trans(
'AfterOrder').
')';
1762 print
'</td><td class="valuefieldcreate">';
1763 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1764 $form->selectAvailabilityDelay(
'',
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1768 if (!empty($conf->expedition->enabled)) {
1769 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1770 $shipping_method_id = $soc->shipping_method_id;
1772 print
'<tr class="field_shipping_method_id"><td class="titlefieldcreate">'.$langs->trans(
'SendingMethod').
'</td><td class="valuefieldcreate">';
1773 print
img_picto(
'',
'object_dollyrevert',
'class="pictofixedwidth"');
1774 print
$form->selectShippingMethod($shipping_method_id,
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1779 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1780 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1782 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">'.$langs->trans(
'Warehouse').
'</td><td class="valuefieldcreate">';
1783 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id,
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1788 print
'<tr class="field_date_livraison"><td class="titlefieldcreate">'.$langs->trans(
"DeliveryDate").
'</td>';
1789 print
'<td class="valuefieldcreate">';
1790 if (isset($conf->global->DATE_LIVRAISON_WEEK_DELAY) && is_numeric($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
1791 $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1792 $syear = date(
"Y", $tmpdte);
1793 $smonth = date(
"m", $tmpdte);
1794 $sday = date(
"d", $tmpdte);
1795 print
$form->selectDate($syear.
"-".$smonth.
"-".$sday,
'date_livraison',
'',
'',
'',
"addprop");
1797 print
$form->selectDate(-1,
'date_livraison',
'',
'',
'',
"addprop", 1, 1);
1802 if (!empty($conf->project->enabled)) {
1803 $langs->load(
"projects");
1804 print
'<tr class="field_projectid">';
1805 print
'<td class="titlefieldcreate">'.$langs->trans(
"Project").
'</td><td class="valuefieldcreate">';
1806 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');
1807 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>';
1813 if (!empty($conf->incoterm->enabled)) {
1814 print
'<tr class="field_incoterm_id">';
1815 print
'<td class="titlefieldcreate"><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $soc->label_incoterms, 1).
'</label></td>';
1816 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1817 print
$form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms :
''), (!empty($soc->location_incoterms) ? $soc->location_incoterms :
''));
1822 print
'<tr class="field_model">';
1823 print
'<td class="titlefieldcreate">'.$langs->trans(
"DefaultModel").
'</td>';
1824 print
'<td class="valuefieldcreate">';
1825 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1827 $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT :
getDolGlobalString(
"PROPALE_ADDON_PDF"));
1828 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1832 if (!empty($conf->multicurrency->enabled)) {
1833 print
'<tr class="field_currency">';
1834 print
'<td class="titlefieldcreate">'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1835 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1836 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code,
'multicurrency_code', 0);
1841 print
'<tr class="field_note_public">';
1842 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1843 print
'<td class="valuefieldcreate">';
1844 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc) ? $objectsrc->note_public :
null));
1845 $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%');
1846 print $doleditor->Create(1);
1849 if (empty($user->socid)) {
1850 print
'<tr class="field_note_private">';
1851 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1852 print
'<td class="valuefieldcreate">';
1853 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private :
null));
1854 $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%');
1855 print $doleditor->Create(1);
1861 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
1864 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1866 if ($origin ==
'contrat') {
1868 $objectsrc->remise_absolue = $remise_absolue;
1869 $objectsrc->remise_percent = $remise_percent;
1870 $objectsrc->update_price(1, - 1, 1);
1873 print
"\n<!-- ".$classname.
" info -->";
1875 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1876 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1877 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1878 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1879 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1881 $newclassname = $classname;
1882 if ($newclassname ==
'Propal') {
1883 $newclassname =
'CommercialProposal';
1884 } elseif ($newclassname ==
'Commande') {
1885 $newclassname =
'Order';
1886 } elseif ($newclassname ==
'Expedition') {
1887 $newclassname =
'Sending';
1888 } elseif ($newclassname ==
'Fichinter') {
1889 $newclassname =
'Intervention';
1892 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
1893 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).
'</td></tr>';
1894 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1895 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1896 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1899 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1900 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1902 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1904 if (!empty($conf->multicurrency->enabled)) {
1905 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1906 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
1907 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
1918 if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
1919 print
'<input type="hidden" name="createmode" value="empty">';
1922 if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
1923 print
'<br><table>';
1927 print
'<td><input type="radio" name="createmode" value="copy"></td>';
1928 print
'<td>'.$langs->trans(
"CopyPropalFrom").
' </td>';
1930 $liste_propal = array();
1931 $liste_propal [0] =
'';
1933 $sql =
"SELECT p.rowid as id, p.ref, s.nom";
1934 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal p";
1935 $sql .=
", ".MAIN_DB_PREFIX.
"societe s";
1936 $sql .=
" WHERE s.rowid = p.fk_soc";
1937 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
1938 $sql .=
" AND p.fk_statut <> 0";
1939 $sql .=
" ORDER BY Id";
1941 $resql = $db->query($sql);
1943 $num = $db->num_rows(
$resql);
1946 $row = $db->fetch_row(
$resql);
1947 $propalRefAndSocName = $row [1].
" - ".$row [2];
1948 $liste_propal [$row [0]] = $propalRefAndSocName;
1951 print
$form->selectarray(
"copie_propal", $liste_propal, 0);
1957 print
'<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1958 print
'<td valign="top" colspan="2">'.$langs->trans(
"CreateEmptyPropal").
'</td></tr>';
1964 $langs->load(
"bills");
1966 print
$form->buttonsSaveCancel(
"CreateDraft");
1972 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1975 $title = $langs->trans(
'ProductsAndServices');
1978 print
'<div class="div-table-responsive-no-min">';
1979 print
'<table class="noborder centpercent">';
1981 $objectsrc->printOriginLinesList();
1986 } elseif ($object->id > 0) {
1990 $object->fetch_thirdparty();
1991 if ($object->thirdparty) {
1992 $soc = $object->thirdparty;
2003 if ($action ==
'clone') {
2005 $formquestion = array(
2008 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')),
2009 array(
'type' =>
'checkbox',
'name' =>
'update_prices',
'label' => $langs->trans(
'PuttingPricesUpToDate'),
'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
2011 if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
2012 $formquestion[] = array(
'type' =>
'date',
'name' =>
'date_delivery',
'label' => $langs->trans(
"DeliveryDate"),
'value' => $object->delivery_date);
2015 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmClonePropal', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2018 if ($action ==
'closeas') {
2020 $formquestion = array(
2021 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))),
2022 array(
'type' =>
'text',
'name' =>
'note_private',
'label' => $langs->trans(
"Note"),
'value' =>
'')
2025 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2027 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && ! empty($user->rights->facture->creer)) {
2028 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2030 $object->fetchObjectLinked();
2032 $eligibleForDepositGeneration =
true;
2034 if (array_key_exists(
'facture', $object->linkedObjects)) {
2035 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2037 $eligibleForDepositGeneration =
false;
2043 if ($eligibleForDepositGeneration && array_key_exists(
'commande', $object->linkedObjects)) {
2044 foreach ($object->linkedObjects[
'commande'] as $order) {
2045 $order->fetchObjectLinked();
2047 if (array_key_exists(
'facture', $order->linkedObjects)) {
2048 foreach ($order->linkedObjects[
'facture'] as $invoice) {
2050 $eligibleForDepositGeneration =
false;
2059 if ($eligibleForDepositGeneration) {
2060 $formquestion[] = array(
2061 'type' =>
'checkbox',
2062 'tdclass' =>
'showonlyifsigned',
2063 'name' =>
'generate_deposit',
2064 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2067 $formquestion[] = array(
2069 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2071 'label' => $langs->trans(
'DateInvoice'),
2076 if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2077 $formquestion[] = array(
2079 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2080 'name' =>
'date_pointoftax',
2081 'label' => $langs->trans(
'DatePointOfTax'),
2088 $form->select_conditions_paiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2089 $paymentTermsSelect = ob_get_clean();
2091 $formquestion[] = array(
2093 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2094 'name' =>
'cond_reglement_id',
2095 'label' => $langs->trans(
'PaymentTerm'),
2096 'value' => $paymentTermsSelect
2099 $formquestion[] = array(
2100 'type' =>
'checkbox',
2101 'tdclass' =>
'showonlyifgeneratedeposit',
2102 'name' =>
'validate_generated_deposit',
2103 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2106 $formquestion[] = array(
2107 'type' =>
'onecolumn',
2110 let signedValue = ' . $object::STATUS_SIGNED .
';
2112 $(document).ready(function() {
2113 $("[name=generate_deposit]").change(function () {
2114 let $self = $(this);
2115 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2117 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2126 $("#statut").change(function() {
2127 let $target = $(".showonlyifsigned").parent(".tagtr");
2129 if ($(this).val() == signedValue) {
2135 $("[name=generate_deposit]").trigger("change");
2140 $("#statut").trigger("change");
2148 if (!empty($conf->notification->enabled)) {
2149 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2150 $notify =
new Notify($db);
2151 $formquestion = array_merge($formquestion, array(
2152 array(
'type' =>
'onecolumn',
'value' => $notify->confirmMessage(
'PROPAL_CLOSE_SIGNED', $object->socid, $object)),
2156 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'SetAcceptedRefused'), $text,
'confirm_closeas', $formquestion,
'', 1, 250);
2157 } elseif ($action ==
'delete') {
2159 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteProp'), $langs->trans(
'ConfirmDeleteProp', $object->ref),
'confirm_delete',
'', 0, 1);
2160 } elseif ($action ==
'reopen') {
2162 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ReOpen'), $langs->trans(
'ConfirmReOpenProp', $object->ref),
'confirm_reopen',
'', 0, 1);
2163 } elseif ($action ==
'ask_deleteline') {
2165 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2166 } elseif ($action ==
'validate') {
2171 $ref = substr($object->ref, 1, 4);
2172 if ($ref ==
'PROV' || $ref ==
'') {
2173 $numref = $object->getNextNumRef($soc);
2174 if (empty($numref)) {
2179 $numref = $object->ref;
2182 $text = $langs->trans(
'ConfirmValidateProp', $numref);
2183 if (!empty($conf->notification->enabled)) {
2184 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2185 $notify =
new Notify($db);
2187 $text .= $notify->confirmMessage(
'PROPAL_VALIDATE', $object->socid, $object);
2192 foreach ($object->lines as $line) {
2193 $res = $line->fetch_product();
2195 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2201 if ($nbMandated > 0) {
2202 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2206 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateProp'), $text,
'confirm_validate',
'', 0, 1);
2212 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2213 if (empty($reshook)) {
2215 } elseif ($reshook > 0) {
2225 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2227 $morehtmlref =
'<div class="refidno">';
2229 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2230 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2232 $morehtmlref .=
'<br><span class="hideonsmartphone">'.$langs->trans(
'ThirdParty').
' : </span>'.$soc->getNomUrl(1,
'customer');
2233 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $soc->id > 0) {
2234 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?socid='.$soc->id.
'&search_societe='.urlencode($soc->name).
'">'.$langs->trans(
"OtherProposals").
'</a>)';
2237 if (!empty($conf->project->enabled)) {
2238 $langs->load(
"projects");
2239 $morehtmlref .=
'<br><span class="paddingrightonly">'.$langs->trans(
'Project').
'</span>';
2240 if ($usercancreate) {
2241 if ($action !=
'classify') {
2242 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2244 if ($action ==
'classify') {
2246 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2247 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2248 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2249 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
2250 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2251 $morehtmlref .=
'</form>';
2253 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2256 if (!empty($object->fk_project)) {
2258 $proj->fetch($object->fk_project);
2259 $morehtmlref .=
': '.$proj->getNomUrl(1);
2261 $morehtmlref .=
' - '.$proj->title;
2268 $morehtmlref .=
'</div>';
2271 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2274 print
'<div class="fichecenter">';
2275 print
'<div class="fichehalfleft">';
2276 print
'<div class="underbanner clearboth"></div>';
2278 print
'<table class="border tableforfield" width="100%">';
2281 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2282 $filterabsolutediscount =
"fk_facture_source IS NULL";
2283 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2285 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2286 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2289 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2291 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2292 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2293 $absolute_discount =
price2num($absolute_discount,
'MT');
2294 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2300 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2301 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2317 print
$form->editfieldkey(
"DatePropal",
'date',
'', $object, $editenable);
2318 print
'</td><td class="valuefield">';
2319 if ($action ==
'editdate' && $usercancreate && $caneditfield) {
2320 print
'<form name="editdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2321 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2322 print
'<input type="hidden" name="action" value="setdate">';
2323 print
$form->selectDate($object->date,
're',
'',
'', 0,
"editdate");
2324 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2327 if ($object->date) {
2338 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2339 print $langs->trans(
'DateEndPropal');
2341 if ($action !=
'editecheance' && $usercancreate && $caneditfield) {
2342 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>';
2344 print
'</tr></table>';
2345 print
'</td><td class="valuefield">';
2346 if ($action ==
'editecheance' && $usercancreate && $caneditfield) {
2347 print
'<form name="editecheance" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2348 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2349 print
'<input type="hidden" name="action" value="setecheance">';
2350 print
$form->selectDate($object->fin_validite,
'ech',
'',
'',
'',
"editecheance");
2351 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2354 if (!empty($object->fin_validite)) {
2356 if ($object->statut ==
Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) {
2368 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2369 print $langs->trans(
'PaymentConditionsShort');
2371 if ($action !=
'editconditions' && $usercancreate && $caneditfield) {
2372 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>';
2374 print
'</tr></table>';
2375 print
'</td><td class="valuefield">';
2376 if ($action ==
'editconditions' && $usercancreate && $caneditfield) {
2377 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 0,
'', 1, $object->deposit_percent);
2379 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 0,
'', 1, $object->deposit_percent);
2385 print
'<tr class="field_mode_reglement_id">';
2386 print
'<td class="titlefieldcreate">';
2387 print
'<table class="nobordernopadding centpercent"><tr><td>';
2388 print $langs->trans(
'PaymentMode');
2390 if ($action !=
'editmode' && $usercancreate && $caneditfield) {
2391 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>';
2393 print
'</tr></table>';
2394 print
'</td><td class="valuefieldcreate">';
2395 if ($action ==
'editmode' && $usercancreate && $caneditfield) {
2396 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2398 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2403 $langs->load(
'deliveries');
2405 print
$form->editfieldkey($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2406 print
'</td><td class="valuefieldedit">';
2407 print
$form->editfieldval($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2412 print
'<tr class="fielddeliverydelay"><td>';
2413 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2414 if (!empty($conf->commande->enabled)) {
2415 print
$form->textwithpicto($langs->trans(
'AvailabilityPeriod'), $langs->trans(
'AvailabilityPeriod').
' ('.$langs->trans(
'AfterOrder').
')');
2417 print $langs->trans(
'AvailabilityPeriod');
2420 if ($action !=
'editavailability' && $usercancreate && $caneditfield) {
2421 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>';
2423 print
'</tr></table>';
2424 print
'</td><td class="valuefield">';
2425 if ($action ==
'editavailability' && $usercancreate && $caneditfield) {
2426 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2428 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2435 if (!empty($conf->expedition->enabled)) {
2437 print
'<table class="nobordernopadding centpercent"><tr><td>';
2438 print $langs->trans(
'SendingMethod');
2440 if ($action !=
'editshippingmethod' && $usercancreate && $caneditfield) {
2441 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>';
2443 print
'</tr></table>';
2444 print
'</td><td class="valuefield">';
2445 if ($action ==
'editshippingmethod' && $usercancreate && $caneditfield) {
2446 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2448 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2455 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
2456 $langs->load(
'stocks');
2457 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2459 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">';
2460 $editenable = $usercancreate;
2461 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2462 print
'</td><td class="valuefieldcreate">';
2463 if ($action ==
'editwarehouse') {
2464 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2466 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2474 print
'<table class="nobordernopadding centpercent"><tr><td>';
2475 print $langs->trans(
'Source');
2477 if ($action !=
'editdemandreason' && $usercancreate) {
2478 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>';
2480 print
'</tr></table>';
2481 print
'</td><td class="valuefield">';
2482 if ($action ==
'editdemandreason' && $usercancreate) {
2483 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2485 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2491 if (!empty($conf->multicurrency->enabled)) {
2495 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2496 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2498 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) {
2499 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>';
2501 print
'</tr></table>';
2502 print
'</td><td class="valuefield">';
2503 if ($object->statut == $object::STATUS_DRAFT && $action ==
'editmulticurrencycode' && $usercancreate) {
2504 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2506 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2511 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2514 print
'<table class="nobordernopadding" width="100%"><tr>';
2516 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2518 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) {
2519 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>';
2521 print
'</tr></table>';
2522 print
'</td><td class="valuefield">';
2523 if ($object->statut == $object::STATUS_DRAFT && ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') && $usercancreate) {
2524 if ($action ==
'actualizemulticurrencyrate') {
2527 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2529 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2530 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2531 print
'<div class="inline-block"> ';
2532 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2540 if ($soc->outstanding_limit) {
2543 print $langs->trans(
'OutstandingBill');
2544 print
'</td><td class="valuefield">';
2545 $arrayoutstandingbills = $soc->getOutstandingBills();
2546 print ($arrayoutstandingbills[
'opened'] > $soc->outstanding_limit ?
img_warning() :
'');
2547 print
price($arrayoutstandingbills[
'opened']).
' / ';
2548 print
price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
2553 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
2556 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2557 print $langs->trans(
'BankAccount');
2559 if ($action !=
'editbankaccount' && $usercancreate) {
2560 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>';
2562 print
'</tr></table>';
2563 print
'</td><td class="valuefield">';
2564 if ($action ==
'editbankaccount') {
2565 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2567 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2573 $tmparray = $object->getTotalWeightVolume();
2574 $totalWeight = $tmparray[
'weight'];
2575 $totalVolume = $tmparray[
'volume'];
2577 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2578 print
'<td class="valuefield">';
2579 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);
2583 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2584 print
'<td class="valuefield">';
2585 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);
2590 if (!empty($conf->incoterm->enabled)) {
2592 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2593 print $langs->trans(
'IncotermLabel');
2594 print
'<td><td class="right">';
2595 if ($action !=
'editincoterm' && $usercancreate && $caneditfield) {
2596 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/comm/propal/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2600 print
'</td></tr></table>';
2602 print
'<td class="valuefield">';
2603 if ($action ==
'editincoterm' && $usercancreate && $caneditfield) {
2604 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2606 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2612 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2617 print
'<div class="fichehalfright">';
2618 print
'<div class="underbanner clearboth"></div>';
2620 print
'<table class="border tableforfield centpercent">';
2622 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2624 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2625 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>';
2629 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2630 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>';
2634 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2635 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>';
2640 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2641 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2645 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
2646 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2650 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2651 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2652 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2655 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2656 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2657 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2662 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
2663 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2672 if (!empty($conf->margin->enabled)) {
2673 $formmargin->displayMarginInfos($object);
2679 print
'<div class="clearboth"></div><br>';
2681 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2682 $blocname =
'contacts';
2683 $title = $langs->trans(
'ContactsAddresses');
2684 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2687 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2688 $blocname =
'notes';
2689 $title = $langs->trans(
'Notes');
2690 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2698 $result = $object->getLinesArray();
2700 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2701 <input type="hidden" name="token" value="' .
newToken().
'">
2702 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2703 <input type="hidden" name="mode" value="">
2704 <input type="hidden" name="page_y" value="">
2705 <input type="hidden" name="id" value="' . $object->id.
'">
2709 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2712 print
'<div class="div-table-responsive-no-min">';
2713 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2714 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2717 if (!empty($object->lines)) {
2718 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2723 if ($action !=
'editline') {
2727 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2728 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2729 if (empty($reshook))
2730 $object->formAddObjectLine(1, $mysoc, $soc);
2733 $reshook = $hookmanager->executeHooks(
'formEditObjectLine',
$parameters, $object, $action);
2737 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2751 if ($action !=
'presend') {
2752 print
'<div class="tabsAction">';
2755 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2757 if (empty($reshook)) {
2758 if ($action !=
'editline') {
2760 if (($object->statut ==
Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
2761 || ($object->statut ==
Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
2762 if ($usercanvalidate) {
2763 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=validate&token='.
newToken().
'">'.$langs->trans(
'Validate').
'</a>';
2765 print
'<a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
'Validate').
'</a>';
2775 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=modif&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
2780 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#reopen').
'"';
2781 print
'>'.$langs->trans(
'ReOpen').
'</a>';
2785 if (empty($user->socid)) {
2788 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2790 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'SendMail').
'</a>';
2797 if ($usercancreateorder) {
2798 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>';
2803 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
2804 if ($object->statut ==
Propal::STATUS_SIGNED && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled))) {
2805 if ($usercancreatepurchaseorder) {
2806 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>';
2812 if (!empty($conf->service->enabled) && !empty($conf->ficheinter->enabled) && $object->statut ==
Propal::STATUS_SIGNED) {
2813 if ($usercancreateintervention) {
2814 $langs->load(
"interventions");
2815 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>';
2821 $langs->load(
"contracts");
2823 if ($usercancreatecontract) {
2824 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>';
2830 if (
isModEnabled(
'facture') && $usercancreateinvoice) {
2831 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>';
2834 $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
2835 if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
2836 if ($usercanclose) {
2837 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'&socid='.$object->socid.
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2839 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2846 if ($usercanclose) {
2847 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=closeas&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#close').
'"';
2848 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2850 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'"';
2851 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2856 if ($usercancreate) {
2857 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>';
2861 if ($usercandelete) {
2862 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'"';
2863 print
'>'.$langs->trans(
'Delete').
'</a>';
2872 if (
GETPOST(
'modelselected')) {
2873 $action =
'presend';
2876 if ($action !=
'presend') {
2877 print
'<div class="fichecenter"><div class="fichehalfleft">';
2878 print
'<a name="builddoc"></a>';
2883 $filedir = $conf->propal->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2884 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2885 $genallowed = $usercanread;
2886 $delallowed = $usercancreate;
2888 print $formfile->showdocuments(
'propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'', 0,
'', $soc->default_lang,
'', $object);
2891 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'propal'));
2893 $compatibleImportElementsList =
false;
2895 $compatibleImportElementsList = array(
'commande',
'propal');
2897 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2900 $useonlinesignature = 1;
2903 print
'<br><!-- Link to sign -->';
2904 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2905 print showOnlineSignatureUrl(
'proposal', $object->ref).
'<br>';
2908 print
'</div><div class="fichehalfright">';
2911 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2913 $somethingshown =
$formactions->showactions($object,
'propal', $socid, 1);
2915 print
'</div></div>';
2919 $modelmail =
'propal_send';
2920 $defaulttopic =
'SendPropalRef';
2921 $diroutput = $conf->propal->multidir_output[$object->entity];
2922 $trackid =
'pro'.$object->id;
2924 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';