41 require
'../../main.inc.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formpropal.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/modules/propale/modules_propale.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/lib/propal.lib.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
63 $langs->loadLangs(array(
'companies',
'propal',
'compta',
'bills',
'orders',
'products',
'deliveries',
'sendings',
'other'));
65 $langs->load(
'incoterm');
68 $langs->load(
'margins');
75 $socid =
GETPOST(
'socid',
'int');
76 $action =
GETPOST(
'action',
'aZ09');
77 $cancel =
GETPOST(
'cancel',
'alpha');
78 $origin =
GETPOST(
'origin',
'alpha');
79 $originid =
GETPOST(
'originid',
'int');
80 $confirm =
GETPOST(
'confirm',
'alpha');
81 $lineid =
GETPOST(
'lineid',
'int');
82 $contactid =
GETPOST(
'contactid',
'int');
83 $projectid =
GETPOST(
'projectid',
'int');
84 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
87 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
88 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
89 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
95 $extrafields->fetch_name_optionals_label($object->table_element);
98 if ($id > 0 || !empty($ref)) {
99 $ret = $object->fetch($id, $ref);
101 $ret = $object->fetch_thirdparty();
110 $hookmanager->initHooks(array(
'propalcard',
'globalcard'));
112 $usercanread = $user->hasRight(
"propal",
"lire");
113 $usercancreate = $user->hasRight(
"propal",
"creer");
114 $usercandelete = $user->hasRight(
"propal",
"supprimer");
116 $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->close)));
117 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)));
118 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->send)));
120 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
121 $usercancreateorder = $user->hasRight(
'commande',
'creer');
122 $usercancreateinvoice = $user->hasRight(
'facture',
'creer');
123 $usercancreatecontract = $user->hasRight(
'contrat',
'creer');
124 $usercancreateintervention = $user->hasRight(
'ficheinter',
'creer');
125 $usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
127 $permissionnote = $usercancreate;
128 $permissiondellink = $usercancreate;
129 $permissiontoedit = $usercancreate;
132 if (!empty($user->socid)) {
133 $socid = $user->socid;
143 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
148 if (empty($reshook)) {
149 $backurlforlist = DOL_URL_ROOT.
'/comm/propal/list.php';
151 if (empty($backtopage) || ($cancel && empty($id))) {
152 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
153 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
154 $backtopage = $backurlforlist;
156 $backtopage = DOL_URL_ROOT.
'/comm/propal/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
162 if (!empty($backtopageforcancel)) {
163 header(
"Location: ".$backtopageforcancel);
165 } elseif (!empty($backtopage)) {
166 header(
"Location: ".$backtopage);
172 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
174 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
176 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
179 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
183 if ($object->id > 0) {
184 if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) {
190 GETPOST(
'date_deliverymonth',
'int'),
191 GETPOST(
'date_deliveryday',
'int'),
192 GETPOST(
'date_deliveryyear',
'int')
194 $date_delivery_old = (empty($object->delivery_date) ? $object->date_livraison : $object->delivery_date);
195 if (!empty($date_delivery_old) && !empty($date_delivery)) {
206 $difference = $date_delivery - $old_date_delivery;
207 if ($difference != 0) {
208 $object->date_livraison = $date_delivery;
209 $object->delivery_date = $date_delivery;
210 foreach ($object->lines as $line) {
211 if (isset($line->date_start)) {
212 $line->date_start = $line->date_start + $difference;
214 if (isset($line->date_end)) {
215 $line->date_end = $line->date_end + $difference;
222 $result = $object->createFromClone($user, $socid, (
GETPOSTISSET(
'entity') ?
GETPOST(
'entity',
'int') :
null), (
GETPOST(
'update_prices',
'aZ') ?
true :
false));
224 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
227 if (count($object->errors) > 0) {
234 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
236 $result = $object->delete($user);
238 header(
'Location: '.DOL_URL_ROOT.
'/comm/propal/list.php?restore_lastsearch_values=1');
241 $langs->load(
"errors");
244 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
246 $result = $object->deleteline($lineid);
249 $object->line_order(
true);
251 $langs->load(
"errors");
255 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
257 $outputlangs = $langs;
260 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
261 $outputlangs->setDefaultLang($newlang);
263 $ret = $object->fetch($id);
265 $object->fetch_thirdparty();
267 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
270 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
272 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
274 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
275 $result = $object->valid($user);
276 if ( $result > 0 && ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) ) {
277 $result = $object->closeProposal($user, $object::STATUS_SIGNED);
280 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
281 $outputlangs = $langs;
284 $newlang =
GETPOST(
'lang_id',
'aZ09');
287 $newlang = $object->thirdparty->default_lang;
289 if (!empty($newlang)) {
291 $outputlangs->setDefaultLang($newlang);
293 $model = $object->model_pdf;
294 $ret = $object->fetch($id);
296 $object->fetch_thirdparty();
299 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
302 $langs->load(
"errors");
303 if (count($object->errors) > 0) {
309 } elseif ($action ==
'setdate' && $usercancreate) {
314 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
318 $result = $object->set_date($user, $datep);
319 if ($result > 0 && !empty($object->duree_validite) && !empty($object->fin_validite)) {
320 $datev = $datep + ($object->duree_validite * 24 * 3600);
321 $result = $object->set_echeance($user, $datev, 1);
325 } elseif (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
326 $outputlangs = $langs;
329 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
330 if (!empty($newlang)) {
332 $outputlangs->setDefaultLang($newlang);
334 $model = $object->model_pdf;
335 $ret = $object->fetch($id);
337 $object->fetch_thirdparty();
340 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
343 } elseif ($action ==
'setecheance' && $usercancreate) {
346 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
347 $outputlangs = $langs;
350 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
351 if (!empty($newlang)) {
353 $outputlangs->setDefaultLang($newlang);
355 $model = $object->model_pdf;
356 $ret = $object->fetch($id);
358 $object->fetch_thirdparty();
361 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
366 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
367 $result = $object->setDeliveryDate($user,
dol_mktime(12, 0, 0,
GETPOST(
'date_livraisonmonth',
'int'),
GETPOST(
'date_livraisonday',
'int'),
GETPOST(
'date_livraisonyear',
'int')));
371 } elseif ($action ==
'setref_client' && $usercancreate) {
373 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
377 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
379 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
380 } elseif ($action ==
'add' && $usercancreate) {
382 $object->socid = $socid;
383 $object->fetch_thirdparty();
387 $duration =
GETPOST(
'duree_validite',
'int');
390 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DatePropal")),
null,
'errors');
394 if (empty($duration)) {
395 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ValidityDuration")),
null,
'errors');
401 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
412 if ($object->fetch(
GETPOST(
'copie_propal',
'int')) > 0) {
414 $object->datep = $datep;
415 $object->date = $datep;
416 $object->date_livraison = $date_delivery;
417 $object->delivery_date = $date_delivery;
418 $object->availability_id =
GETPOST(
'availability_id');
419 $object->demand_reason_id =
GETPOST(
'demand_reason_id');
420 $object->fk_delivery_address =
GETPOST(
'fk_address',
'int');
421 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
422 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
423 $object->duree_validite = $duration;
424 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
425 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
426 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
427 $object->fk_account =
GETPOST(
'fk_account',
'int');
430 $object->socid =
GETPOST(
'socid',
'int');
431 $object->contact_id =
GETPOST(
'contactid',
'int');
432 $object->fk_project =
GETPOST(
'projectid',
'int');
433 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
434 $object->author = $user->id;
435 $object->user_author_id = $user->id;
436 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
437 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
439 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
440 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
446 $object->ref_client =
GETPOST(
'ref_client');
447 $object->datep = $datep;
448 $object->date = $datep;
449 $object->date_livraison = $date_delivery;
450 $object->delivery_date = $date_delivery;
451 $object->availability_id =
GETPOST(
'availability_id',
'int');
452 $object->demand_reason_id =
GETPOST(
'demand_reason_id',
'int');
453 $object->fk_delivery_address =
GETPOST(
'fk_address',
'int');
454 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
455 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
457 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
458 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
459 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
460 $object->fk_account =
GETPOST(
'fk_account',
'int');
461 $object->contact_id =
GETPOST(
'contactid',
'int');
462 $object->fk_project =
GETPOST(
'projectid',
'int');
463 $object->model_pdf =
GETPOST(
'model');
464 $object->author = $user->id;
465 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
466 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
467 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
468 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
470 $object->origin =
GETPOST(
'origin');
471 $object->origin_id =
GETPOST(
'originid');
475 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
479 $ret = $extrafields->setOptionalsFromPost(
null, $object);
487 if ($origin && $originid) {
489 $element = $subelement = $origin;
490 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
491 $element = $regs [1];
492 $subelement = $regs [2];
496 if ($element ==
'order') {
497 $element = $subelement =
'commande';
499 if ($element ==
'propal') {
500 $element =
'comm/propal';
501 $subelement =
'propal';
503 if ($element ==
'contract') {
504 $element = $subelement =
'contrat';
506 if ($element ==
'inter') {
507 $element = $subelement =
'ficheinter';
509 if ($element ==
'shipping') {
510 $element = $subelement =
'expedition';
513 $object->origin = $origin;
514 $object->origin_id = $originid;
517 $object->linked_objects [$object->origin] = $object->origin_id;
518 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
519 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
522 $id = $object->create($user);
526 $classname = ucfirst($subelement);
527 $srcobject =
new $classname($db);
529 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
530 $result = $srcobject->fetch($object->origin_id);
533 $lines = $srcobject->lines;
534 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
535 $srcobject->fetch_lines();
536 $lines = $srcobject->lines;
540 $num = count($lines);
541 for ($i = 0; $i < $num; $i++) {
542 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
543 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
546 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
550 if ($lines[$i]->date_debut_prevue) {
551 $date_start = $lines[$i]->date_debut_prevue;
553 if ($lines[$i]->date_debut_reel) {
554 $date_start = $lines[$i]->date_debut_reel;
556 if ($lines[$i]->date_start) {
557 $date_start = $lines[$i]->date_start;
562 if ($lines[$i]->date_fin_prevue) {
563 $date_end = $lines[$i]->date_fin_prevue;
565 if ($lines[$i]->date_fin_reel) {
566 $date_end = $lines[$i]->date_fin_reel;
568 if ($lines[$i]->date_end) {
569 $date_end = $lines[$i]->date_end;
573 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
578 if (method_exists($lines[$i],
'fetch_optionals')) {
579 $lines[$i]->fetch_optionals();
580 $array_options = $lines[$i]->array_options;
583 $tva_tx = $lines[$i]->tva_tx;
584 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
585 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
588 $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);
599 if ($result > 0 && $lines[$i]->product_type == 9) {
600 $fk_parent_line = $result;
606 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
622 $id = $object->create($user);
627 if (
GETPOST(
'contactid') > 0) {
628 $result = $object->add_contact(
GETPOST(
'contactid'),
'CUSTOMER',
'external');
635 if (!empty($conf->global->PROPOSAL_AUTO_ADD_AUTHOR_AS_CONTACT)) {
636 $result = $object->add_contact($user->id,
'SALESREPFOLL',
'internal');
639 setEventMessages($langs->trans(
"ErrorFailedToAddUserAsContact"),
null,
'errors');
647 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
648 $outputlangs = $langs;
651 $newlang =
GETPOST(
'lang_id',
'aZ09');
654 $newlang = $object->thirdparty->default_lang;
656 if (!empty($newlang)) {
658 $outputlangs->setDefaultLang($newlang);
660 $model = $object->model_pdf;
662 $ret = $object->fetch($id);
663 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
669 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
682 } elseif ($action ==
'classifybilled' && $usercanclose) {
686 $result = $object->classifyBilled($user, 0,
'');
697 } elseif ($action ==
'confirm_closeas' && $usercanclose && !
GETPOST(
'cancel',
'alpha')) {
699 if (!(
GETPOST(
'statut',
'int') > 0)) {
700 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CloseAs")),
null,
'errors');
702 } elseif (
GETPOST(
'statut',
'int') == $object::STATUS_SIGNED ||
GETPOST(
'statut',
'int') == $object::STATUS_NOTSIGNED) {
703 $locationTarget =
'';
705 if ($object->statut == $object::STATUS_VALIDATED || ( ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) && $object->statut == $object::STATUS_DRAFT)) {
708 $result = $object->closeProposal($user,
GETPOST(
'statut',
'int'),
GETPOST(
'note_private',
'restricthtml'));
714 $locationTarget = DOL_URL_ROOT .
'/comm/propal/card.php?id=' . $object->id;
719 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
722 !$error &&
GETPOST(
'statut',
'int') == $object::STATUS_SIGNED &&
GETPOST(
'generate_deposit',
'alpha') ==
'on'
723 && !empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
725 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
728 $forceFields = array();
731 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
738 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
748 if ($deposit && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
749 $ret = $deposit->fetch($deposit->id);
750 $outputlangs = $langs;
754 $outputlangs->setDefaultLang($deposit->thirdparty->default_lang);
755 $outputlangs->load(
'products');
758 $result = $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
765 if ($locationTarget) {
766 header(
'Location: ' . $locationTarget);
775 } elseif ($action ==
'confirm_reopen' && $usercanclose && !
GETPOST(
'cancel',
'alpha')) {
781 $result = $object->reopen($user, empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE));
793 } elseif ($action ==
'import_lines_from_object'
794 && $user->rights->propal->creer
798 $fromElement =
GETPOST(
'fromelement');
799 $fromElementid =
GETPOST(
'fromelementid');
800 $importLines =
GETPOST(
'line_checkbox');
802 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
803 if ($fromElement ==
'commande') {
805 $lineClassName =
'OrderLine';
806 } elseif ($fromElement ==
'propal') {
807 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
808 $lineClassName =
'PropaleLigne';
810 $nextRang = count($object->lines) + 1;
813 foreach ($importLines as $lineId) {
814 $lineId = intval($lineId);
815 $originLine =
new $lineClassName($db);
816 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
817 $originLine->fetch_optionals();
818 $desc = $originLine->desc;
819 $pu_ht = $originLine->subprice;
820 $qty = $originLine->qty;
821 $txtva = $originLine->tva_tx;
822 $txlocaltax1 = $originLine->localtax1_tx;
823 $txlocaltax2 = $originLine->localtax2_tx;
824 $fk_product = $originLine->fk_product;
825 $remise_percent = $originLine->remise_percent;
826 $date_start = $originLine->date_start;
827 $date_end = $originLine->date_end;
829 $info_bits = $originLine->info_bits;
830 $fk_remise_except = $originLine->fk_remise_except;
831 $price_base_type =
'HT';
833 $type = $originLine->product_type;
835 $special_code = $originLine->special_code;
836 $origin = $originLine->element;
837 $origin_id = $originLine->id;
839 $fk_fournprice = $originLine->fk_fournprice;
840 $pa_ht = $originLine->pa_ht;
841 $label = $originLine->label;
842 $array_options = $originLine->array_options;
843 $situation_percent = 100;
845 $fk_unit = $originLine->fk_unit;
846 $pu_ht_devise = $originLine->multicurrency_subprice;
848 $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);
866 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
869 $actiontypecode =
'AC_OTH_AUTO';
870 $triggersendname =
'PROPAL_SENTBYMAIL';
871 $autocopy =
'MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
872 $trackid =
'pro'.$object->id;
873 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
877 if ($action ==
'modif' && $usercancreate) {
878 $object->setDraft($user);
880 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
882 $outputlangs = $langs;
885 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
886 $outputlangs->setDefaultLang($newlang);
888 $ret = $object->fetch($id);
890 $object->fetch_thirdparty();
892 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
894 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
895 if (
GETPOST(
"remise_id",
"int")) {
896 if ($object->id > 0) {
897 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
903 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
905 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
906 $vat_rate = str_replace(
'*',
'', $vat_rate);
907 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
908 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
909 foreach ($object->lines as $line) {
910 $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);
912 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
914 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
915 $remise_percent = str_replace(
'*',
'', $remise_percent);
916 foreach ($object->lines as $line) {
917 $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);
919 } elseif ($action ==
'addline' && $usercancreate) {
925 $price_ht_devise =
'';
927 $price_ttc_devise =
'';
931 if (
GETPOST(
'price_ht') !==
'') {
934 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
937 if (
GETPOST(
'price_ttc') !==
'') {
940 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
944 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
945 if ($prod_entry_mode ==
'free') {
949 $idprod =
GETPOST(
'idprod',
'int');
955 if (empty($remise_percent)) {
960 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
961 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
963 if (is_array($extralabelsline)) {
965 foreach ($extralabelsline as $key => $value) {
966 unset($_POST[
"options_".$key]);
970 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
971 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
975 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
976 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
979 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
980 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
984 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
985 if ($combinations =
GETPOST(
'combinations',
'array')) {
989 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
990 $idprod = $res->fk_product_child;
992 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
998 $propal_qty_requirement = (!empty($conf->global->PROPAL_ENABLE_NEGATIVE_QTY) ? ($qty >= 0 || $qty <= 0) : $qty >= 0);
999 if (!$error && $propal_qty_requirement && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
1004 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
1014 if (!empty($idprod) && $idprod > 0) {
1016 $prod->fetch($idprod);
1018 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
1023 if (empty($tva_tx)) {
1028 $pu_ht = $prod->price;
1029 $pu_ttc = $prod->price_ttc;
1030 $price_min = $prod->price_min;
1031 $price_min_ttc = $prod->price_min_ttc;
1032 $price_base_type = $prod->price_base_type;
1035 if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
1036 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
1037 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
1038 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
1039 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
1040 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
1041 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1042 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
1043 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
1045 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
1046 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
1049 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1051 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
1055 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
1057 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1060 if (count($prodcustprice->lines) > 0) {
1061 $pu_ht =
price($prodcustprice->lines[0]->price);
1062 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
1063 $price_min =
price($prodcustprice->lines[0]->price_min);
1064 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
1065 $price_base_type = $prodcustprice->lines[0]->price_base_type;
1066 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1067 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1068 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1070 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1071 if (empty($tva_tx)) {
1076 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
1078 if ($prod->prices_by_qty[0]) {
1083 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
1084 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1088 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1089 $pu_ht = $priceforthequantityarray[
'unitprice'];
1091 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1097 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1099 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
1104 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
1105 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1109 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1110 $pu_ht = $priceforthequantityarray[
'unitprice'];
1112 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1120 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
1121 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
1124 if (!empty($price_ht) || $price_ht ===
'0') {
1126 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1127 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
1129 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1130 } elseif ($tmpvat != $tmpprodvat) {
1132 if ($price_base_type !=
'HT') {
1133 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1135 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1142 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1143 $outputlangs = $langs;
1145 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1146 $newlang =
GETPOST(
'lang_id',
'aZ09');
1148 if (empty($newlang)) {
1149 $newlang = $object->thirdparty->default_lang;
1151 if (!empty($newlang)) {
1152 $outputlangs =
new Translate(
"", $conf);
1153 $outputlangs->setDefaultLang($newlang);
1156 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
1158 $desc = $prod->description;
1162 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1166 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1167 $desc = $product_desc;
1169 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1173 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
1176 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1177 $outputlangs = $langs;
1179 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
1180 $newlang =
GETPOST(
'lang_id',
'alpha');
1182 if (empty($newlang)) {
1183 $newlang = $object->thirdparty->default_lang;
1185 if (!empty($newlang)) {
1186 $outputlangs =
new Translate(
"", $conf);
1187 $outputlangs->setDefaultLang($newlang);
1188 $outputlangs->load(
'products');
1190 if (!empty($prod->customcode)) {
1191 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1193 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1196 if (!empty($prod->country_code)) {
1197 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
1200 if (!empty($prod->customcode)) {
1201 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1203 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1206 if (!empty($prod->country_code)) {
1207 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
1214 $type = $prod->type;
1215 $fk_unit = $prod->fk_unit;
1219 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1220 if (empty($tva_tx)) {
1223 $tva_tx = str_replace(
'*',
'', $tva_tx);
1224 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1225 $desc = $product_desc;
1227 $fk_unit =
GETPOST(
'units',
'alpha');
1228 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1229 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
1231 if ($pu_ttc && !$pu_ht) {
1232 $price_base_type =
'TTC';
1242 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
1243 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
1253 $pu_equivalent = $pu_ht;
1254 $pu_equivalent_ttc = $pu_ttc;
1255 $currency_tx = $object->multicurrency_tx;
1259 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1260 $pu_equivalent = $pu_ht_devise * $currency_tx;
1262 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1263 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1281 if ($usermustrespectpricemin) {
1282 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
1283 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1286 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1287 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1295 $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);
1300 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1302 $outputlangs = $langs;
1304 $outputlangs =
new Translate(
"", $conf);
1305 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1306 $outputlangs->setDefaultLang($newlang);
1308 $ret = $object->fetch($id);
1310 $object->fetch_thirdparty();
1312 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1315 unset($_POST[
'prod_entry_mode']);
1317 unset($_POST[
'qty']);
1318 unset($_POST[
'type']);
1319 unset($_POST[
'remise_percent']);
1320 unset($_POST[
'price_ht']);
1321 unset($_POST[
'multicurrency_price_ht']);
1322 unset($_POST[
'price_ttc']);
1323 unset($_POST[
'tva_tx']);
1324 unset($_POST[
'product_ref']);
1325 unset($_POST[
'product_label']);
1326 unset($_POST[
'product_desc']);
1327 unset($_POST[
'fournprice']);
1328 unset($_POST[
'buying_price']);
1329 unset($_POST[
'np_marginRate']);
1330 unset($_POST[
'np_markRate']);
1331 unset($_POST[
'dp_desc']);
1332 unset($_POST[
'idprod']);
1333 unset($_POST[
'units']);
1335 unset($_POST[
'date_starthour']);
1336 unset($_POST[
'date_startmin']);
1337 unset($_POST[
'date_startsec']);
1338 unset($_POST[
'date_startday']);
1339 unset($_POST[
'date_startmonth']);
1340 unset($_POST[
'date_startyear']);
1341 unset($_POST[
'date_endhour']);
1342 unset($_POST[
'date_endmin']);
1343 unset($_POST[
'date_endsec']);
1344 unset($_POST[
'date_endday']);
1345 unset($_POST[
'date_endmonth']);
1346 unset($_POST[
'date_endyear']);
1354 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1362 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1368 $vat_rate = str_replace(
'*',
'', $vat_rate);
1369 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1370 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1385 if (empty($remise_percent)) {
1386 $remise_percent = 0;
1390 $pu_equivalent = $pu_ht;
1391 $pu_equivalent_ttc = $pu_ttc;
1393 $currency_tx = $object->multicurrency_tx;
1397 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1398 $pu_equivalent = $pu_ht_devise * $currency_tx;
1400 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1401 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1416 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1417 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1419 if (is_array($extralabelsline)) {
1421 foreach ($extralabelsline as $key => $value) {
1422 unset($_POST[
"options_".$key]);
1427 $special_code =
GETPOST(
'special_code',
'int');
1433 $productid =
GETPOST(
'productid',
'int');
1434 if (!empty($productid)) {
1436 $res = $product->fetch($productid);
1438 $type = $product->type;
1441 $price_min = $product->price_min;
1442 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1443 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1445 $price_min_ttc = $product->price_min_ttc;
1446 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1447 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1454 if ($usermustrespectpricemin) {
1455 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
1456 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1459 $action =
'editline';
1460 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1461 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1464 $action =
'editline';
1469 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1473 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1481 if (empty($user->rights->margins->creer)) {
1482 foreach ($object->lines as &$line) {
1483 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1484 $fournprice = $line->fk_fournprice;
1485 $buyingprice = $line->pa_ht;
1494 $price_base_type =
'HT';
1495 if (empty($pu) && !empty($pu_ttc)) {
1497 $price_base_type =
'TTC';
1500 $result = $object->updateline(
GETPOST(
'lineid',
'int'), $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, $price_base_type, $info_bits, $special_code,
GETPOST(
'fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options,
GETPOST(
"units"), $pu_ht_devise);
1505 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1507 $outputlangs = $langs;
1509 $outputlangs =
new Translate(
"", $conf);
1510 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1511 $outputlangs->setDefaultLang($newlang);
1513 $ret = $object->fetch($id);
1515 $object->fetch_thirdparty();
1517 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1520 unset($_POST[
'qty']);
1521 unset($_POST[
'type']);
1522 unset($_POST[
'productid']);
1523 unset($_POST[
'remise_percent']);
1524 unset($_POST[
'price_ht']);
1525 unset($_POST[
'multicurrency_price_ht']);
1526 unset($_POST[
'price_ttc']);
1527 unset($_POST[
'tva_tx']);
1528 unset($_POST[
'product_ref']);
1529 unset($_POST[
'product_label']);
1530 unset($_POST[
'product_desc']);
1531 unset($_POST[
'fournprice']);
1532 unset($_POST[
'buying_price']);
1534 unset($_POST[
'date_starthour']);
1535 unset($_POST[
'date_startmin']);
1536 unset($_POST[
'date_startsec']);
1537 unset($_POST[
'date_startday']);
1538 unset($_POST[
'date_startmonth']);
1539 unset($_POST[
'date_startyear']);
1540 unset($_POST[
'date_endhour']);
1541 unset($_POST[
'date_endmin']);
1542 unset($_POST[
'date_endsec']);
1543 unset($_POST[
'date_endday']);
1544 unset($_POST[
'date_endmonth']);
1545 unset($_POST[
'date_endyear']);
1552 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1553 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1555 } elseif ($action ==
'classin' && $usercancreate) {
1557 $object->setProject(
GETPOST(
'projectid',
'int'));
1558 } elseif ($action ==
'setavailability' && $usercancreate) {
1560 $result = $object->set_availability($user,
GETPOST(
'availability_id',
'int'));
1561 } elseif ($action ==
'setdemandreason' && $usercancreate) {
1563 $result = $object->set_demand_reason($user,
GETPOST(
'demand_reason_id',
'int'));
1564 } elseif ($action ==
'setconditions' && $usercancreate) {
1566 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
1567 } elseif ($action ==
'setremisepercent' && $usercancreate) {
1568 $result = $object->set_remise_percent($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
1569 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
1570 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
1571 } elseif ($action ==
'setmode' && $usercancreate) {
1573 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
1574 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
1576 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
1577 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
1579 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
1580 } elseif ($action ==
'setbankaccount' && $usercancreate) {
1582 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
1583 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
1585 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
1586 } elseif ($action ==
'setwarehouse' && $usercancreate) {
1588 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
1589 } elseif ($action ==
'update_extras') {
1590 $object->oldcopy =
dol_clone($object, 2);
1593 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1598 $result = $object->insertExtraFields(
'PROPAL_MODIFY');
1605 $action =
'edit_extras';
1609 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1610 if ($action ==
'addcontact') {
1611 if ($object->id > 0) {
1614 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1618 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1621 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1622 $langs->load(
"errors");
1623 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1628 } elseif ($action ==
'swapstatut') {
1630 if ($object->fetch($id) > 0) {
1631 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1635 } elseif ($action ==
'deletecontact') {
1637 $object->fetch($id);
1638 $result = $object->delete_contact($lineid);
1641 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1650 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
1651 $permissiontoadd = $usercancreate;
1652 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1668 $title = $object->ref.
" - ".$langs->trans(
'Card');
1669 if ($action ==
'create') {
1670 $title = $langs->trans(
"NewPropal");
1672 $help_url =
'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
1679 if ($action ==
'create') {
1680 $currency_code = $conf->currency;
1684 $cond_reglement_id = $mode_reglement_id = 0;
1688 $res = $soc->fetch($socid);
1691 $cond_reglement_id = $soc->cond_reglement_id;
1694 $mode_reglement_id = $soc->mode_reglement_id;
1699 if (!empty($origin) && !empty($originid)) {
1701 $element = $subelement = $origin;
1703 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1704 $element = $regs[1];
1705 $subelement = $regs[2];
1708 if ($element ==
'project') {
1709 $projectid = $originid;
1712 if ($element ==
'order' || $element ==
'commande') {
1713 $element = $subelement =
'commande';
1715 if ($element ==
'propal') {
1716 $element =
'comm/propal';
1717 $subelement =
'propal';
1719 if ($element ==
'contract') {
1720 $element = $subelement =
'contrat';
1722 if ($element ==
'shipping') {
1723 $element = $subelement =
'expedition';
1728 $classname = ucfirst($subelement);
1729 $objectsrc =
new $classname($db);
1730 $objectsrc->fetch($originid);
1731 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1732 $objectsrc->fetch_lines();
1734 $objectsrc->fetch_thirdparty();
1736 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
1737 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1739 $soc = $objectsrc->thirdparty;
1741 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1742 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1743 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1744 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1745 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1746 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
1749 $objectsrc->fetch_optionals();
1750 $object->array_options = $objectsrc->array_options;
1753 if (!empty($objectsrc->multicurrency_code)) {
1754 $currency_code = $objectsrc->multicurrency_code;
1756 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1757 $currency_tx = $objectsrc->multicurrency_tx;
1762 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1763 $currency_code = $soc->multicurrency_code;
1768 if (empty($cond_reglement_id)) {
1769 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
1772 if (empty($mode_reglement_id)) {
1773 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
1777 if ($soc->fk_warehouse > 0) {
1778 $warehouse_id = $soc->fk_warehouse;
1780 if (
isModEnabled(
'stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1781 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1782 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1784 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1785 $warehouse_id = $user->fk_warehouse;
1789 print
'<form name="addprop" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1790 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1791 print
'<input type="hidden" name="action" value="add">';
1792 if ($origin !=
'project' && $originid) {
1793 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1794 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1795 } elseif ($origin ==
'project' && !empty($projectid)) {
1796 print
'<input type="hidden" name="projectid" value="'.$projectid.
'">';
1801 print
'<table class="border centpercent">';
1804 print
'<tr class="field_ref"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td class="valuefieldcreate">'.$langs->trans(
"Draft").
'</td></tr>';
1807 print
'<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans(
'RefCustomer').
'</td><td class="valuefieldcreate">';
1808 print
'<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:
GETPOST(
'ref_client')).
'"></td>';
1812 print
'<tr class="field_socid">';
1813 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1814 $shipping_method_id = 0;
1816 print
'<td class="valuefieldcreate">';
1817 print $soc->getNomUrl(1,
'customer');
1818 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1820 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1821 $shipping_method_id = $soc->shipping_method_id;
1825 print
'<td class="valuefieldcreate">';
1826 print
img_picto(
'',
'company').$form->select_company(
'',
'socid',
'((s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1)',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 maxwidth500 widthcentpercentminusxx');
1828 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1829 print
'<script type="text/javascript">
1830 $(document).ready(function() {
1831 $("#socid").change(function() {
1832 console.log("We have changed the company - Reload page");
1833 var socid = $(this).val();
1835 $("input[name=action]").val("create");
1836 $("form[name=addprop]").submit();
1841 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>';
1848 print
'<tr class="field_contactid"><td class="titlefieldcreate">'.$langs->trans(
"DefaultContact").
'</td><td class="valuefieldcreate">';
1850 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1,
'',
'', 0,
'minwidth300');
1854 print
'<tr class="field_discount_info"><td class="titlefieldcreate">'.$langs->trans(
'Discounts').
'</td><td class="valuefieldcreate">';
1856 $absolute_discount = $soc->getAvailableDiscounts();
1860 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1861 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1866 print
'<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'DatePropal').
'</td><td class="valuefieldcreate">';
1867 print
$form->selectDate(
'',
'',
'',
'',
'',
"addprop", 1, 1);
1871 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>';
1874 print
'<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1876 print
$form->getSelectConditionsPaiements($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));
1880 print
'<tr class="field_mode_reglement_id"><td class="titlefieldcreate">'.$langs->trans(
'PaymentMode').
'</td><td class="valuefieldcreate">';
1881 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1882 print
$form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
1886 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) &&
isModEnabled(
"banque")) {
1887 print
'<tr class="field_fk_account"><td class="titlefieldcreate">'.$langs->trans(
'BankAccount').
'</td><td class="valuefieldcreate">';
1888 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($soc->fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1893 print
'<tr class="field_demand_reason_id"><td class="titlefieldcreate">'.$langs->trans(
'Source').
'</td><td class="valuefieldcreate">';
1894 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1895 $form->selectInputReason((
GETPOSTISSET(
'demand_reason_id') ?
GETPOST(
'demand_reason_id',
'int') :
''),
'demand_reason_id',
"SRC_PROP", 1,
'maxwidth200 widthcentpercentminusx');
1899 print
'<tr class="field_availability_id"><td class="titlefieldcreate">'.$langs->trans(
'AvailabilityPeriod');
1901 print
' ('.$langs->trans(
'AfterOrder').
')';
1903 print
'</td><td class="valuefieldcreate">';
1904 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1905 $form->selectAvailabilityDelay((
GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id',
'int') :
''),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1910 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1911 $shipping_method_id = $soc->shipping_method_id;
1913 print
'<tr class="field_shipping_method_id"><td class="titlefieldcreate">'.$langs->trans(
'SendingMethod').
'</td><td class="valuefieldcreate">';
1914 print
img_picto(
'',
'object_dollyrevert',
'class="pictofixedwidth"');
1915 $form->selectShippingMethod((
GETPOSTISSET(
'shipping_method_id') ?
GETPOST(
'shipping_method_id',
'int') : $shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1920 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1921 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1923 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">'.$langs->trans(
'Warehouse').
'</td><td class="valuefieldcreate">';
1924 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id,
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1929 print
'<tr class="field_date_livraison"><td class="titlefieldcreate">'.$langs->trans(
"DeliveryDate").
'</td>';
1930 print
'<td class="valuefieldcreate">';
1931 if (isset($conf->global->DATE_LIVRAISON_WEEK_DELAY) && is_numeric($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
1932 $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1933 $syear = date(
"Y", $tmpdte);
1934 $smonth = date(
"m", $tmpdte);
1935 $sday = date(
"d", $tmpdte);
1936 print
$form->selectDate($syear.
"-".$smonth.
"-".$sday,
'date_livraison',
'',
'',
'',
"addprop");
1938 print
$form->selectDate(-1,
'date_livraison',
'',
'',
'',
"addprop", 1, 1);
1944 $langs->load(
"projects");
1945 print
'<tr class="field_projectid">';
1946 print
'<td class="titlefieldcreate">'.$langs->trans(
"Project").
'</td><td class="valuefieldcreate">';
1947 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');
1948 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>';
1955 print
'<tr class="field_incoterm_id">';
1956 print
'<td class="titlefieldcreate"><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $soc->label_incoterms, 1).
'</label></td>';
1957 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1958 print
$form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms :
''), (!empty($soc->location_incoterms) ? $soc->location_incoterms :
''));
1963 print
'<tr class="field_model">';
1964 print
'<td class="titlefieldcreate">'.$langs->trans(
"DefaultModel").
'</td>';
1965 print
'<td class="valuefieldcreate">';
1966 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1968 $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT :
getDolGlobalString(
"PROPALE_ADDON_PDF"));
1969 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1974 print
'<tr class="field_currency">';
1975 print
'<td class="titlefieldcreate">'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1976 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1977 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code,
'multicurrency_code', 0);
1982 print
'<tr class="field_note_public">';
1983 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1984 print
'<td class="valuefieldcreate">';
1985 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc) ? $objectsrc->note_public :
null));
1986 $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%');
1987 print $doleditor->Create(1);
1990 if (empty($user->socid)) {
1991 print
'<tr class="field_note_private">';
1992 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1993 print
'<td class="valuefieldcreate">';
1994 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private :
null));
1995 $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%');
1996 print $doleditor->Create(1);
2002 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
2005 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2007 if ($origin ==
'contrat') {
2009 $objectsrc->remise_absolue = $remise_absolue;
2010 $objectsrc->remise_percent = $remise_percent;
2011 $objectsrc->update_price(1,
'auto', 1);
2014 print
"\n<!-- ".$classname.
" info -->";
2016 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2017 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2018 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2019 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2020 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2022 $newclassname = $classname;
2023 if ($newclassname ==
'Propal') {
2024 $newclassname =
'CommercialProposal';
2025 } elseif ($newclassname ==
'Commande') {
2026 $newclassname =
'Order';
2027 } elseif ($newclassname ==
'Expedition') {
2028 $newclassname =
'Sending';
2029 } elseif ($newclassname ==
'Fichinter') {
2030 $newclassname =
'Intervention';
2033 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2034 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).
'</td></tr>';
2035 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
2036 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2037 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
2040 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2041 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
2043 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
2046 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2047 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2048 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2059 if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
2060 print
'<input type="hidden" name="createmode" value="empty">';
2063 if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
2064 print
'<br><table>';
2068 print
'<td><input type="radio" name="createmode" value="copy"></td>';
2069 print
'<td>'.$langs->trans(
"CopyPropalFrom").
' </td>';
2071 $liste_propal = array();
2072 $liste_propal [0] =
'';
2074 $sql =
"SELECT p.rowid as id, p.ref, s.nom";
2075 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal p";
2076 $sql .=
", ".MAIN_DB_PREFIX.
"societe s";
2077 $sql .=
" WHERE s.rowid = p.fk_soc";
2078 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
2079 $sql .=
" AND p.fk_statut <> 0";
2080 $sql .=
" ORDER BY Id";
2082 $resql = $db->query($sql);
2084 $num = $db->num_rows(
$resql);
2087 $row = $db->fetch_row(
$resql);
2088 $propalRefAndSocName = $row[1].
" - ".$row[2];
2089 $liste_propal[$row[0]] = $propalRefAndSocName;
2092 print
$form->selectarray(
"copie_propal", $liste_propal, 0);
2098 print
'<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
2099 print
'<td valign="top" colspan="2">'.$langs->trans(
"CreateEmptyPropal").
'</td></tr>';
2105 $langs->load(
"bills");
2107 print
$form->buttonsSaveCancel(
"CreateDraft");
2113 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2116 $title = $langs->trans(
'ProductsAndServices');
2119 print
'<div class="div-table-responsive-no-min">';
2120 print
'<table class="noborder centpercent">';
2122 $objectsrc->printOriginLinesList();
2127 } elseif ($object->id > 0) {
2131 $object->fetch_thirdparty();
2132 if ($object->thirdparty) {
2133 $soc = $object->thirdparty;
2144 if ($action ==
'clone') {
2146 $formquestion = array(
2149 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')),
2150 array(
'type' =>
'checkbox',
'name' =>
'update_prices',
'label' => $langs->trans(
'PuttingPricesUpToDate'),
'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
2152 if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
2153 $formquestion[] = array(
'type' =>
'date',
'name' =>
'date_delivery',
'label' => $langs->trans(
"DeliveryDate"),
'value' => $object->delivery_date);
2156 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmClonePropal', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2159 if ($action ==
'closeas') {
2161 $formquestion = array();
2162 if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2163 $formquestion[] = 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)));
2165 $formquestion[] = array(
'type' =>
'text',
'name' =>
'note_private',
'label' => $langs->trans(
"Note"),
'value' =>
'');
2167 if (
getDolGlobalInt(
'PROPOSAL_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2172 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2174 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)) {
2175 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2177 $object->fetchObjectLinked();
2179 $eligibleForDepositGeneration =
true;
2181 if (array_key_exists(
'facture', $object->linkedObjects)) {
2182 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2184 $eligibleForDepositGeneration =
false;
2190 if ($eligibleForDepositGeneration && array_key_exists(
'commande', $object->linkedObjects)) {
2191 foreach ($object->linkedObjects[
'commande'] as $order) {
2192 $order->fetchObjectLinked();
2194 if (array_key_exists(
'facture', $order->linkedObjects)) {
2195 foreach ($order->linkedObjects[
'facture'] as $invoice) {
2197 $eligibleForDepositGeneration =
false;
2206 if ($eligibleForDepositGeneration) {
2207 $formquestion[] = array(
2208 'type' =>
'checkbox',
2209 'tdclass' =>
'showonlyifsigned',
2210 'name' =>
'generate_deposit',
2211 'morecss' =>
'margintoponly marginbottomonly',
2212 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2215 $formquestion[] = array(
2217 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2219 'label' => $langs->trans(
'DateInvoice'),
2224 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2225 $formquestion[] = array(
2227 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2228 'name' =>
'date_pointoftax',
2229 'label' => $langs->trans(
'DatePointOfTax'),
2235 $paymentTermsSelect =
$form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 1,
'minwidth200');
2237 $formquestion[] = array(
2239 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2240 'name' =>
'cond_reglement_id',
2241 'label' => $langs->trans(
'PaymentTerm'),
2242 'value' => $paymentTermsSelect
2245 $formquestion[] = array(
2246 'type' =>
'checkbox',
2247 'tdclass' =>
'showonlyifgeneratedeposit',
2248 'name' =>
'validate_generated_deposit',
2249 'morecss' =>
'margintoponly marginbottomonly',
2250 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2253 $formquestion[] = array(
2254 'type' =>
'onecolumn',
2257 let signedValue = ' . $object::STATUS_SIGNED .
';
2259 $(document).ready(function() {
2260 $("[name=generate_deposit]").change(function () {
2261 let $self = $(this);
2262 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2264 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2273 $("#statut").change(function() {
2274 let $target = $(".showonlyifsigned").parent(".tagtr");
2276 if ($(this).val() == signedValue) {
2282 $("[name=generate_deposit]").trigger("change");
2287 $("#statut").trigger("change");
2297 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2298 $notify =
new Notify($db);
2299 $formquestion = array_merge($formquestion, array(
2300 array(
'type' =>
'onecolumn',
'value' => $notify->confirmMessage(
'PROPAL_CLOSE_SIGNED', $object->socid, $object)),
2304 if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2305 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'SetAcceptedRefused'),
'',
'confirm_closeas', $formquestion,
'', 1, 250);
2307 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?statut=3&id=' . $object->id, $langs->trans(
'Close'),
'',
'confirm_closeas', $formquestion,
'', 1, 250);
2309 } elseif ($action ==
'delete') {
2311 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteProp'), $langs->trans(
'ConfirmDeleteProp', $object->ref),
'confirm_delete',
'', 0, 1);
2312 } elseif ($action ==
'reopen') {
2314 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ReOpen'), $langs->trans(
'ConfirmReOpenProp', $object->ref),
'confirm_reopen',
'', 0, 1);
2315 } elseif ($action ==
'ask_deleteline') {
2317 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2318 } elseif ($action ==
'validate') {
2323 $ref = substr($object->ref, 1, 4);
2324 if ($ref ==
'PROV' || $ref ==
'') {
2325 $numref = $object->getNextNumRef($soc);
2326 if (empty($numref)) {
2331 $numref = $object->ref;
2334 $text = $langs->trans(
'ConfirmValidateProp', $numref);
2336 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2337 $notify =
new Notify($db);
2339 $text .= $notify->confirmMessage(
'PROPAL_VALIDATE', $object->socid, $object);
2344 foreach ($object->lines as $line) {
2345 $res = $line->fetch_product();
2347 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2353 if ($nbMandated > 0) {
2354 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2358 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateProp'), $text,
'confirm_validate',
'', 0, 1);
2364 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2365 if (empty($reshook)) {
2367 } elseif ($reshook > 0) {
2377 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2379 $morehtmlref =
'<div class="refidno">';
2381 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2382 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE :
''),
'',
null,
null,
'', 1);
2384 $morehtmlref .=
'<br><span class="hideonsmartphone">'.$langs->trans(
'ThirdParty').
' : </span>'.$soc->getNomUrl(1,
'customer');
2385 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $soc->id > 0) {
2386 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?socid='.$soc->id.
'&search_societe='.urlencode($soc->name).
'">'.$langs->trans(
"OtherProposals").
'</a>)';
2390 $langs->load(
"projects");
2391 $morehtmlref .=
'<br>';
2392 if ($usercancreate) {
2393 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2394 if ($action !=
'classify') {
2395 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2397 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2399 if (!empty($object->fk_project)) {
2401 $proj->fetch($object->fk_project);
2402 $morehtmlref .= $proj->getNomUrl(1);
2404 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2409 $morehtmlref .=
'</div>';
2412 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2415 print
'<div class="fichecenter">';
2416 print
'<div class="fichehalfleft">';
2417 print
'<div class="underbanner clearboth"></div>';
2419 print
'<table class="border tableforfield centpercent">';
2422 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2423 $filterabsolutediscount =
"fk_facture_source IS NULL";
2424 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2426 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2427 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2430 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2432 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2433 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2434 $absolute_discount =
price2num($absolute_discount,
'MT');
2435 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2441 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2442 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2458 print
$form->editfieldkey(
"DatePropal",
'date',
'', $object, $editenable);
2459 print
'</td><td class="valuefield">';
2460 if ($action ==
'editdate' && $usercancreate && $caneditfield) {
2461 print
'<form name="editdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2462 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2463 print
'<input type="hidden" name="action" value="setdate">';
2464 print
$form->selectDate($object->date,
're',
'',
'', 0,
"editdate");
2465 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2468 if ($object->date) {
2479 print
'<table class="nobordernopadding centpercent"><tr><td>';
2480 print $langs->trans(
'DateEndPropal');
2482 if ($action !=
'editecheance' && $usercancreate && $caneditfield) {
2483 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>';
2485 print
'</tr></table>';
2486 print
'</td><td class="valuefield">';
2487 if ($action ==
'editecheance' && $usercancreate && $caneditfield) {
2488 print
'<form name="editecheance" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2489 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2490 print
'<input type="hidden" name="action" value="setecheance">';
2491 print
$form->selectDate($object->fin_validite,
'ech',
'',
'',
'',
"editecheance");
2492 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2495 if (!empty($object->fin_validite)) {
2497 if ($object->statut ==
Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) {
2509 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2510 print $langs->trans(
'PaymentConditionsShort');
2512 if ($action !=
'editconditions' && $usercancreate && $caneditfield) {
2513 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>';
2515 print
'</tr></table>';
2516 print
'</td><td class="valuefield">';
2517 if ($action ==
'editconditions' && $usercancreate && $caneditfield) {
2518 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 0,
'', 1, $object->deposit_percent);
2520 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 0,
'', 1, $object->deposit_percent);
2526 print
'<tr class="field_mode_reglement_id">';
2527 print
'<td class="titlefieldcreate">';
2528 print
'<table class="nobordernopadding centpercent"><tr><td>';
2529 print $langs->trans(
'PaymentMode');
2531 if ($action !=
'editmode' && $usercancreate && $caneditfield) {
2532 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>';
2534 print
'</tr></table>';
2535 print
'</td><td class="valuefieldcreate">';
2536 if ($action ==
'editmode' && $usercancreate && $caneditfield) {
2537 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2539 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2544 $langs->load(
'deliveries');
2546 print
$form->editfieldkey($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2547 print
'</td><td class="valuefieldedit">';
2548 print
$form->editfieldval($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2553 print
'<tr class="fielddeliverydelay"><td>';
2554 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2556 print
$form->textwithpicto($langs->trans(
'AvailabilityPeriod'), $langs->trans(
'AvailabilityPeriod').
' ('.$langs->trans(
'AfterOrder').
')');
2558 print $langs->trans(
'AvailabilityPeriod');
2561 if ($action !=
'editavailability' && $usercancreate && $caneditfield) {
2562 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>';
2564 print
'</tr></table>';
2565 print
'</td><td class="valuefield">';
2566 if ($action ==
'editavailability' && $usercancreate && $caneditfield) {
2567 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2569 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2578 print
'<table class="nobordernopadding centpercent"><tr><td>';
2579 print $langs->trans(
'SendingMethod');
2581 if ($action !=
'editshippingmethod' && $usercancreate && $caneditfield) {
2582 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>';
2584 print
'</tr></table>';
2585 print
'</td><td class="valuefield">';
2586 if ($action ==
'editshippingmethod' && $usercancreate && $caneditfield) {
2587 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2589 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2596 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
2597 $langs->load(
'stocks');
2598 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2600 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">';
2601 $editenable = $usercancreate;
2602 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2603 print
'</td><td class="valuefieldcreate">';
2604 if ($action ==
'editwarehouse') {
2605 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2607 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2615 print
'<table class="nobordernopadding centpercent"><tr><td>';
2616 print $langs->trans(
'Source');
2618 if ($action !=
'editdemandreason' && $usercancreate) {
2619 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>';
2621 print
'</tr></table>';
2622 print
'</td><td class="valuefield">';
2623 if ($action ==
'editdemandreason' && $usercancreate) {
2624 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2626 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2636 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2637 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2639 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) {
2640 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>';
2642 print
'</tr></table>';
2643 print
'</td><td class="valuefield">';
2644 if ($object->statut == $object::STATUS_DRAFT && $action ==
'editmulticurrencycode' && $usercancreate) {
2645 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2647 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2652 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2655 print
'<table class="nobordernopadding" width="100%"><tr>';
2657 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2659 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) {
2660 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>';
2662 print
'</tr></table>';
2663 print
'</td><td class="valuefield">';
2664 if ($object->statut == $object::STATUS_DRAFT && ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') && $usercancreate) {
2665 if ($action ==
'actualizemulticurrencyrate') {
2668 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2670 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2671 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2672 print
'<div class="inline-block"> ';
2673 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2681 if ($soc->outstanding_limit) {
2684 print $langs->trans(
'OutstandingBill');
2685 print
'</td><td class="valuefield">';
2686 $arrayoutstandingbills = $soc->getOutstandingBills();
2687 print ($arrayoutstandingbills[
'opened'] > $soc->outstanding_limit ?
img_warning() :
'');
2688 print
price($arrayoutstandingbills[
'opened']).
' / ';
2689 print
price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
2694 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) &&
isModEnabled(
"banque")) {
2697 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2698 print $langs->trans(
'BankAccount');
2700 if ($action !=
'editbankaccount' && $usercancreate) {
2701 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>';
2703 print
'</tr></table>';
2704 print
'</td><td class="valuefield">';
2705 if ($action ==
'editbankaccount') {
2706 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2708 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2714 $tmparray = $object->getTotalWeightVolume();
2715 $totalWeight = $tmparray[
'weight'];
2716 $totalVolume = $tmparray[
'volume'];
2718 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2719 print
'<td class="valuefield">';
2720 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);
2724 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2725 print
'<td class="valuefield">';
2726 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);
2733 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2734 print $langs->trans(
'IncotermLabel');
2735 print
'<td><td class="right">';
2736 if ($action !=
'editincoterm' && $usercancreate && $caneditfield) {
2737 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/comm/propal/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2741 print
'</td></tr></table>';
2743 print
'<td class="valuefield">';
2744 if ($action ==
'editincoterm' && $usercancreate && $caneditfield) {
2745 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2747 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2753 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2758 print
'<div class="fichehalfright">';
2759 print
'<div class="underbanner clearboth"></div>';
2761 print
'<table class="border tableforfield centpercent">';
2763 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2765 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2766 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>';
2770 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2771 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>';
2775 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2776 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>';
2781 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2782 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2786 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
2787 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2791 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2792 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2793 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2796 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2797 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2798 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2803 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
2804 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2814 $formmargin->displayMarginInfos($object);
2820 print
'<div class="clearboth"></div><br>';
2822 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2823 $blocname =
'contacts';
2824 $title = $langs->trans(
'ContactsAddresses');
2825 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2828 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2829 $blocname =
'notes';
2830 $title = $langs->trans(
'Notes');
2831 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2839 $result = $object->getLinesArray();
2843 global $inputalsopricewithtax;
2844 $inputalsopricewithtax = 1;
2846 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2847 <input type="hidden" name="token" value="' .
newToken().
'">
2848 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2849 <input type="hidden" name="mode" value="">
2850 <input type="hidden" name="page_y" value="">
2851 <input type="hidden" name="id" value="' . $object->id.
'">
2855 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2858 print
'<div class="div-table-responsive-no-min">';
2859 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2860 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2863 if (!empty($object->lines)) {
2864 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2869 if ($action !=
'editline') {
2871 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2872 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2873 if (empty($reshook))
2874 $object->formAddObjectLine(1, $mysoc, $soc);
2877 $reshook = $hookmanager->executeHooks(
'formEditObjectLine',
$parameters, $object, $action);
2881 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2895 if ($action !=
'presend') {
2896 print
'<div class="tabsAction">';
2899 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2901 if (empty($reshook)) {
2902 if ($action !=
'editline') {
2904 if (($object->statut ==
Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
2905 || ($object->statut ==
Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
2906 if ($usercanvalidate) {
2907 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=validate&token='.
newToken().
'">'.(empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) ? $langs->trans(
'Validate') : $langs->trans(
'ValidateAndSign')).
'</a>';
2909 print
'<a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
'Validate').
'</a>';
2919 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=modif&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
2924 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#reopen').
'"';
2925 print
'>'.$langs->trans(
'ReOpen').
'</a>';
2929 if (empty($user->socid)) {
2931 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'', $usercansend);
2937 if ($usercancreateorder) {
2938 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>';
2943 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
2945 if ($usercancreatepurchaseorder) {
2946 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>';
2953 if ($usercancreateintervention) {
2954 $langs->load(
"interventions");
2955 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>';
2961 $langs->load(
"contracts");
2963 if ($usercancreatecontract) {
2964 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>';
2970 if (
isModEnabled(
'facture') && $usercancreateinvoice) {
2971 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>';
2974 $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
2975 if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
2976 if ($usercanclose) {
2977 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'&socid='.$object->socid.
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2979 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2984 if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2987 if ($usercanclose) {
2988 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=closeas&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#close').
'"';
2989 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2991 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'"';
2992 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2998 print
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&token='.newToken().
'&action=closeas&token='.
newToken() . (empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#close') .
'"';
2999 print
'>' . $langs->trans(
'SetRefusedAndClose') .
'</a>';
3004 if ($usercancreate) {
3005 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>';
3009 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $usercandelete);
3017 if (
GETPOST(
'modelselected')) {
3018 $action =
'presend';
3021 if ($action !=
'presend') {
3022 print
'<div class="fichecenter"><div class="fichehalfleft">';
3023 print
'<a name="builddoc"></a>';
3028 $filedir = $conf->propal->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
3029 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
3030 $genallowed = $usercanread;
3031 $delallowed = $usercancreate;
3033 print $formfile->showdocuments(
'propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'', 0,
'', $soc->default_lang,
'', $object);
3036 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'propal'));
3038 $compatibleImportElementsList =
false;
3040 $compatibleImportElementsList = array(
'commande',
'propal');
3042 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
3045 $useonlinesignature = 1;
3048 print
'<br><!-- Link to sign -->';
3049 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
3050 print showOnlineSignatureUrl(
'proposal', $object->ref).
'<br>';
3053 print
'</div><div class="fichehalfright">';
3056 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3058 $somethingshown =
$formactions->showactions($object,
'propal', $socid, 1);
3060 print
'</div></div>';
3064 $modelmail =
'propal_send';
3065 $defaulttopic =
'SendPropalRef';
3066 $diroutput = $conf->propal->multidir_output[$object->entity];
3067 $trackid =
'pro'.$object->id;
3069 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';