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) {
704 if ($object->statut == $object::STATUS_VALIDATED || ( ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) && $object->statut == $object::STATUS_DRAFT)) {
707 $result = $object->closeProposal($user,
GETPOST(
'statut',
'int'),
GETPOST(
'note_private',
'restricthtml'));
714 $locationTarget =
'';
716 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
719 !$error &&
GETPOST(
'statut',
'int') == $object::STATUS_SIGNED &&
GETPOST(
'generate_deposit',
'alpha') ==
'on'
720 && !empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
722 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
725 $forceFields = array();
728 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
735 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
745 if ($deposit && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
746 $ret = $deposit->fetch($deposit->id);
747 $outputlangs = $langs;
751 $outputlangs->setDefaultLang($deposit->thirdparty->default_lang);
752 $outputlangs->load(
'products');
755 $result = $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
762 if ($locationTarget) {
763 header(
'Location: ' . $locationTarget);
772 } elseif ($action ==
'confirm_reopen' && $usercanclose && !
GETPOST(
'cancel',
'alpha')) {
778 $result = $object->reopen($user, empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE));
790 } elseif ($action ==
'import_lines_from_object'
791 && $user->rights->propal->creer
795 $fromElement =
GETPOST(
'fromelement');
796 $fromElementid =
GETPOST(
'fromelementid');
797 $importLines =
GETPOST(
'line_checkbox');
799 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
800 if ($fromElement ==
'commande') {
802 $lineClassName =
'OrderLine';
803 } elseif ($fromElement ==
'propal') {
804 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
805 $lineClassName =
'PropaleLigne';
807 $nextRang = count($object->lines) + 1;
810 foreach ($importLines as $lineId) {
811 $lineId = intval($lineId);
812 $originLine =
new $lineClassName($db);
813 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
814 $originLine->fetch_optionals();
815 $desc = $originLine->desc;
816 $pu_ht = $originLine->subprice;
817 $qty = $originLine->qty;
818 $txtva = $originLine->tva_tx;
819 $txlocaltax1 = $originLine->localtax1_tx;
820 $txlocaltax2 = $originLine->localtax2_tx;
821 $fk_product = $originLine->fk_product;
822 $remise_percent = $originLine->remise_percent;
823 $date_start = $originLine->date_start;
824 $date_end = $originLine->date_end;
826 $info_bits = $originLine->info_bits;
827 $fk_remise_except = $originLine->fk_remise_except;
828 $price_base_type =
'HT';
830 $type = $originLine->product_type;
832 $special_code = $originLine->special_code;
833 $origin = $originLine->element;
834 $origin_id = $originLine->id;
836 $fk_fournprice = $originLine->fk_fournprice;
837 $pa_ht = $originLine->pa_ht;
838 $label = $originLine->label;
839 $array_options = $originLine->array_options;
840 $situation_percent = 100;
842 $fk_unit = $originLine->fk_unit;
843 $pu_ht_devise = $originLine->multicurrency_subprice;
845 $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);
863 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
866 $actiontypecode =
'AC_OTH_AUTO';
867 $triggersendname =
'PROPAL_SENTBYMAIL';
868 $autocopy =
'MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
869 $trackid =
'pro'.$object->id;
870 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
874 if ($action ==
'modif' && $usercancreate) {
875 $object->setDraft($user);
877 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
879 $outputlangs = $langs;
882 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
883 $outputlangs->setDefaultLang($newlang);
885 $ret = $object->fetch($id);
887 $object->fetch_thirdparty();
889 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
891 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
892 if (
GETPOST(
"remise_id",
"int")) {
893 if ($object->id > 0) {
894 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
900 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
902 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
903 $vat_rate = str_replace(
'*',
'', $vat_rate);
904 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
905 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
906 foreach ($object->lines as $line) {
907 $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);
909 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
911 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
912 $remise_percent = str_replace(
'*',
'', $remise_percent);
913 foreach ($object->lines as $line) {
914 $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);
916 } elseif ($action ==
'addline' && $usercancreate) {
922 $price_ht_devise =
'';
924 $price_ttc_devise =
'';
928 if (
GETPOST(
'price_ht') !==
'') {
931 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
934 if (
GETPOST(
'price_ttc') !==
'') {
937 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
941 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
942 if ($prod_entry_mode ==
'free') {
946 $idprod =
GETPOST(
'idprod',
'int');
952 if (empty($remise_percent)) {
957 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
958 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
960 if (is_array($extralabelsline)) {
962 foreach ($extralabelsline as $key => $value) {
963 unset($_POST[
"options_".$key]);
967 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
968 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
972 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
973 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
976 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
977 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
981 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
982 if ($combinations =
GETPOST(
'combinations',
'array')) {
986 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
987 $idprod = $res->fk_product_child;
989 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
995 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
1000 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
1010 if (!empty($idprod) && $idprod > 0) {
1012 $prod->fetch($idprod);
1014 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
1019 if (empty($tva_tx)) {
1024 $pu_ht = $prod->price;
1025 $pu_ttc = $prod->price_ttc;
1026 $price_min = $prod->price_min;
1027 $price_min_ttc = $prod->price_min_ttc;
1028 $price_base_type = $prod->price_base_type;
1031 if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
1032 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
1033 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
1034 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
1035 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
1036 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
1037 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1038 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
1039 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
1041 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
1042 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
1045 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1047 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
1051 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
1053 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1056 if (count($prodcustprice->lines) > 0) {
1057 $pu_ht =
price($prodcustprice->lines[0]->price);
1058 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
1059 $price_min =
price($prodcustprice->lines[0]->price_min);
1060 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
1061 $price_base_type = $prodcustprice->lines[0]->price_base_type;
1062 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1063 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1064 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1066 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1067 if (empty($tva_tx)) {
1072 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
1074 if ($prod->prices_by_qty[0]) {
1079 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
1080 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1084 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1085 $pu_ht = $priceforthequantityarray[
'unitprice'];
1087 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1093 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1095 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
1100 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
1101 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1105 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1106 $pu_ht = $priceforthequantityarray[
'unitprice'];
1108 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1116 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
1117 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
1120 if (!empty($price_ht) || $price_ht ===
'0') {
1122 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1123 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
1125 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1126 } elseif ($tmpvat != $tmpprodvat) {
1128 if ($price_base_type !=
'HT') {
1129 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1131 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1138 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1139 $outputlangs = $langs;
1141 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1142 $newlang =
GETPOST(
'lang_id',
'aZ09');
1144 if (empty($newlang)) {
1145 $newlang = $object->thirdparty->default_lang;
1147 if (!empty($newlang)) {
1148 $outputlangs =
new Translate(
"", $conf);
1149 $outputlangs->setDefaultLang($newlang);
1152 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
1154 $desc = $prod->description;
1158 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1162 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1163 $desc = $product_desc;
1165 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1169 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
1172 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1173 $outputlangs = $langs;
1175 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
1176 $newlang =
GETPOST(
'lang_id',
'alpha');
1178 if (empty($newlang)) {
1179 $newlang = $object->thirdparty->default_lang;
1181 if (!empty($newlang)) {
1182 $outputlangs =
new Translate(
"", $conf);
1183 $outputlangs->setDefaultLang($newlang);
1184 $outputlangs->load(
'products');
1186 if (!empty($prod->customcode)) {
1187 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1189 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1192 if (!empty($prod->country_code)) {
1193 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
1196 if (!empty($prod->customcode)) {
1197 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1199 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1202 if (!empty($prod->country_code)) {
1203 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
1210 $type = $prod->type;
1211 $fk_unit = $prod->fk_unit;
1215 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1216 if (empty($tva_tx)) {
1219 $tva_tx = str_replace(
'*',
'', $tva_tx);
1220 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1221 $desc = $product_desc;
1223 $fk_unit =
GETPOST(
'units',
'alpha');
1224 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1225 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
1227 if ($pu_ttc && !$pu_ht) {
1228 $price_base_type =
'TTC';
1240 $pu_equivalent = $pu_ht;
1241 $pu_equivalent_ttc = $pu_ttc;
1242 $currency_tx = $object->multicurrency_tx;
1246 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1247 $pu_equivalent = $pu_ht_devise * $currency_tx;
1249 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1250 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1254 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
1255 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
1265 if ($usermustrespectpricemin) {
1266 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1267 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1270 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1271 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1279 $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);
1284 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1286 $outputlangs = $langs;
1288 $outputlangs =
new Translate(
"", $conf);
1289 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1290 $outputlangs->setDefaultLang($newlang);
1292 $ret = $object->fetch($id);
1294 $object->fetch_thirdparty();
1296 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1299 unset($_POST[
'prod_entry_mode']);
1301 unset($_POST[
'qty']);
1302 unset($_POST[
'type']);
1303 unset($_POST[
'remise_percent']);
1304 unset($_POST[
'price_ht']);
1305 unset($_POST[
'multicurrency_price_ht']);
1306 unset($_POST[
'price_ttc']);
1307 unset($_POST[
'tva_tx']);
1308 unset($_POST[
'product_ref']);
1309 unset($_POST[
'product_label']);
1310 unset($_POST[
'product_desc']);
1311 unset($_POST[
'fournprice']);
1312 unset($_POST[
'buying_price']);
1313 unset($_POST[
'np_marginRate']);
1314 unset($_POST[
'np_markRate']);
1315 unset($_POST[
'dp_desc']);
1316 unset($_POST[
'idprod']);
1317 unset($_POST[
'units']);
1319 unset($_POST[
'date_starthour']);
1320 unset($_POST[
'date_startmin']);
1321 unset($_POST[
'date_startsec']);
1322 unset($_POST[
'date_startday']);
1323 unset($_POST[
'date_startmonth']);
1324 unset($_POST[
'date_startyear']);
1325 unset($_POST[
'date_endhour']);
1326 unset($_POST[
'date_endmin']);
1327 unset($_POST[
'date_endsec']);
1328 unset($_POST[
'date_endday']);
1329 unset($_POST[
'date_endmonth']);
1330 unset($_POST[
'date_endyear']);
1338 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1342 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1351 $vat_rate = str_replace(
'*',
'', $vat_rate);
1352 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1353 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1368 if (empty($remise_percent)) {
1369 $remise_percent = 0;
1373 $pu_equivalent = $pu_ht;
1374 $pu_equivalent_ttc = $pu_ttc;
1375 $currency_tx = $object->multicurrency_tx;
1379 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1380 $pu_equivalent = $pu_ht_devise * $currency_tx;
1382 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1383 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1387 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1388 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1390 if (is_array($extralabelsline)) {
1392 foreach ($extralabelsline as $key => $value) {
1393 unset($_POST[
"options_".$key]);
1398 $special_code =
GETPOST(
'special_code',
'int');
1404 $productid =
GETPOST(
'productid',
'int');
1405 if (!empty($productid)) {
1407 $res = $product->fetch($productid);
1409 $type = $product->type;
1412 $price_min = $product->price_min;
1413 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1414 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1416 $price_min_ttc = $product->price_min_ttc;
1417 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1418 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1424 if ($usermustrespectpricemin) {
1425 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1426 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1429 $action =
'editline';
1430 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1431 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1434 $action =
'editline';
1439 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1443 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1451 if (empty($user->rights->margins->creer)) {
1452 foreach ($object->lines as &$line) {
1453 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1454 $fournprice = $line->fk_fournprice;
1455 $buyingprice = $line->pa_ht;
1464 $price_base_type =
'HT';
1465 if (empty($pu) && !empty($pu_ttc)) {
1467 $price_base_type =
'TTC';
1470 $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);
1475 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1477 $outputlangs = $langs;
1479 $outputlangs =
new Translate(
"", $conf);
1480 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $object->thirdparty->default_lang);
1481 $outputlangs->setDefaultLang($newlang);
1483 $ret = $object->fetch($id);
1485 $object->fetch_thirdparty();
1487 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1490 unset($_POST[
'qty']);
1491 unset($_POST[
'type']);
1492 unset($_POST[
'productid']);
1493 unset($_POST[
'remise_percent']);
1494 unset($_POST[
'price_ht']);
1495 unset($_POST[
'multicurrency_price_ht']);
1496 unset($_POST[
'price_ttc']);
1497 unset($_POST[
'tva_tx']);
1498 unset($_POST[
'product_ref']);
1499 unset($_POST[
'product_label']);
1500 unset($_POST[
'product_desc']);
1501 unset($_POST[
'fournprice']);
1502 unset($_POST[
'buying_price']);
1504 unset($_POST[
'date_starthour']);
1505 unset($_POST[
'date_startmin']);
1506 unset($_POST[
'date_startsec']);
1507 unset($_POST[
'date_startday']);
1508 unset($_POST[
'date_startmonth']);
1509 unset($_POST[
'date_startyear']);
1510 unset($_POST[
'date_endhour']);
1511 unset($_POST[
'date_endmin']);
1512 unset($_POST[
'date_endsec']);
1513 unset($_POST[
'date_endday']);
1514 unset($_POST[
'date_endmonth']);
1515 unset($_POST[
'date_endyear']);
1522 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1523 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1525 } elseif ($action ==
'classin' && $usercancreate) {
1527 $object->setProject(
GETPOST(
'projectid',
'int'));
1528 } elseif ($action ==
'setavailability' && $usercancreate) {
1530 $result = $object->set_availability($user,
GETPOST(
'availability_id',
'int'));
1531 } elseif ($action ==
'setdemandreason' && $usercancreate) {
1533 $result = $object->set_demand_reason($user,
GETPOST(
'demand_reason_id',
'int'));
1534 } elseif ($action ==
'setconditions' && $usercancreate) {
1536 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
1537 } elseif ($action ==
'setremisepercent' && $usercancreate) {
1538 $result = $object->set_remise_percent($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
1539 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
1540 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
1541 } elseif ($action ==
'setmode' && $usercancreate) {
1543 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
1544 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
1546 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
1547 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
1549 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
1550 } elseif ($action ==
'setbankaccount' && $usercancreate) {
1552 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
1553 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
1555 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
1556 } elseif ($action ==
'setwarehouse' && $usercancreate) {
1558 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
1559 } elseif ($action ==
'update_extras') {
1563 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1568 $result = $object->insertExtraFields(
'PROPAL_MODIFY');
1575 $action =
'edit_extras';
1579 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1580 if ($action ==
'addcontact') {
1581 if ($object->id > 0) {
1584 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1588 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1591 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1592 $langs->load(
"errors");
1593 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1598 } elseif ($action ==
'swapstatut') {
1600 if ($object->fetch($id) > 0) {
1601 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1605 } elseif ($action ==
'deletecontact') {
1607 $object->fetch($id);
1608 $result = $object->delete_contact($lineid);
1611 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1620 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
1621 $permissiontoadd = $usercancreate;
1622 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1638 $title = $object->ref.
" - ".$langs->trans(
'Card');
1639 if ($action ==
'create') {
1640 $title = $langs->trans(
"NewPropal");
1642 $help_url =
'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
1649 if ($action ==
'create') {
1650 $currency_code = $conf->currency;
1656 $res = $soc->fetch($socid);
1660 if (!empty($origin) && !empty($originid)) {
1662 $element = $subelement = $origin;
1664 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1665 $element = $regs[1];
1666 $subelement = $regs[2];
1669 if ($element ==
'project') {
1670 $projectid = $originid;
1673 if ($element ==
'order' || $element ==
'commande') {
1674 $element = $subelement =
'commande';
1676 if ($element ==
'propal') {
1677 $element =
'comm/propal';
1678 $subelement =
'propal';
1680 if ($element ==
'contract') {
1681 $element = $subelement =
'contrat';
1683 if ($element ==
'shipping') {
1684 $element = $subelement =
'expedition';
1689 $classname = ucfirst($subelement);
1690 $objectsrc =
new $classname($db);
1691 $objectsrc->fetch($originid);
1692 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1693 $objectsrc->fetch_lines();
1695 $objectsrc->fetch_thirdparty();
1697 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
1698 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1700 $soc = $objectsrc->thirdparty;
1702 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1703 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1704 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1705 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1706 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1707 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
1710 $objectsrc->fetch_optionals();
1711 $object->array_options = $objectsrc->array_options;
1714 if (!empty($objectsrc->multicurrency_code)) {
1715 $currency_code = $objectsrc->multicurrency_code;
1717 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1718 $currency_tx = $objectsrc->multicurrency_tx;
1723 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1724 $currency_code = $soc->multicurrency_code;
1729 if ($soc->fk_warehouse > 0) {
1730 $warehouse_id = $soc->fk_warehouse;
1732 if (
isModEnabled(
'stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1733 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1734 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1736 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1737 $warehouse_id = $user->fk_warehouse;
1741 print
'<form name="addprop" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1742 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1743 print
'<input type="hidden" name="action" value="add">';
1744 if ($origin !=
'project' && $originid) {
1745 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1746 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1747 } elseif ($origin ==
'project' && !empty($projectid)) {
1748 print
'<input type="hidden" name="projectid" value="'.$projectid.
'">';
1753 print
'<table class="border centpercent">';
1756 print
'<tr class="field_ref"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td class="valuefieldcreate">'.$langs->trans(
"Draft").
'</td></tr>';
1759 print
'<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans(
'RefCustomer').
'</td><td class="valuefieldcreate">';
1760 print
'<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:
GETPOST(
'ref_client')).
'"></td>';
1764 print
'<tr class="field_socid">';
1765 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1766 $shipping_method_id = 0;
1768 print
'<td class="valuefieldcreate">';
1769 print $soc->getNomUrl(1,
'customer');
1770 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1772 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1773 $shipping_method_id = $soc->shipping_method_id;
1777 print
'<td class="valuefieldcreate">';
1778 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');
1780 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1781 print
'<script type="text/javascript">
1782 $(document).ready(function() {
1783 $("#socid").change(function() {
1784 console.log("We have changed the company - Reload page");
1785 var socid = $(this).val();
1787 $("input[name=action]").val("create");
1788 $("form[name=addprop]").submit();
1793 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>';
1800 print
'<tr class="field_contactid"><td class="titlefieldcreate">'.$langs->trans(
"DefaultContact").
'</td><td class="valuefieldcreate">';
1802 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1,
'',
'', 0,
'minwidth300');
1806 print
'<tr class="field_discount_info"><td class="titlefieldcreate">'.$langs->trans(
'Discounts').
'</td><td class="valuefieldcreate">';
1808 $absolute_discount = $soc->getAvailableDiscounts();
1812 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1813 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1818 print
'<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'DatePropal').
'</td><td class="valuefieldcreate">';
1819 print
$form->selectDate(
'',
'',
'',
'',
'',
"addprop", 1, 1);
1823 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>';
1826 print
'<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1828 print
$form->getSelectConditionsPaiements((
GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id',
'int') != 0) ?
GETPOST(
'cond_reglement_id',
'int') : $soc->cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'', (
GETPOSTISSET(
'cond_reglement_id_deposit_percent') ?
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha') : $soc->deposit_percent));
1832 print
'<tr class="field_mode_reglement_id"><td class="titlefieldcreate">'.$langs->trans(
'PaymentMode').
'</td><td class="valuefieldcreate">';
1833 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1834 print
$form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOST(
'mode_reglement_id',
'int') != 0) ?
GETPOST(
'mode_reglement_id',
'int') : $soc->mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
1838 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) &&
isModEnabled(
"banque")) {
1839 print
'<tr class="field_fk_account"><td class="titlefieldcreate">'.$langs->trans(
'BankAccount').
'</td><td class="valuefieldcreate">';
1840 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($soc->fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1845 print
'<tr class="field_demand_reason_id"><td class="titlefieldcreate">'.$langs->trans(
'Source').
'</td><td class="valuefieldcreate">';
1846 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1847 $form->selectInputReason((
GETPOSTISSET(
'demand_reason_id') ?
GETPOST(
'demand_reason_id',
'int') :
''),
'demand_reason_id',
"SRC_PROP", 1,
'maxwidth200 widthcentpercentminusx');
1851 print
'<tr class="field_availability_id"><td class="titlefieldcreate">'.$langs->trans(
'AvailabilityPeriod');
1853 print
' ('.$langs->trans(
'AfterOrder').
')';
1855 print
'</td><td class="valuefieldcreate">';
1856 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1857 $form->selectAvailabilityDelay((
GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id',
'int') :
''),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1862 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1863 $shipping_method_id = $soc->shipping_method_id;
1865 print
'<tr class="field_shipping_method_id"><td class="titlefieldcreate">'.$langs->trans(
'SendingMethod').
'</td><td class="valuefieldcreate">';
1866 print
img_picto(
'',
'object_dollyrevert',
'class="pictofixedwidth"');
1867 $form->selectShippingMethod((
GETPOSTISSET(
'shipping_method_id') ?
GETPOST(
'shipping_method_id',
'int') : $shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1872 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1873 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1875 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">'.$langs->trans(
'Warehouse').
'</td><td class="valuefieldcreate">';
1876 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id,
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1881 print
'<tr class="field_date_livraison"><td class="titlefieldcreate">'.$langs->trans(
"DeliveryDate").
'</td>';
1882 print
'<td class="valuefieldcreate">';
1883 if (isset($conf->global->DATE_LIVRAISON_WEEK_DELAY) && is_numeric($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
1884 $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1885 $syear = date(
"Y", $tmpdte);
1886 $smonth = date(
"m", $tmpdte);
1887 $sday = date(
"d", $tmpdte);
1888 print
$form->selectDate($syear.
"-".$smonth.
"-".$sday,
'date_livraison',
'',
'',
'',
"addprop");
1890 print
$form->selectDate(-1,
'date_livraison',
'',
'',
'',
"addprop", 1, 1);
1896 $langs->load(
"projects");
1897 print
'<tr class="field_projectid">';
1898 print
'<td class="titlefieldcreate">'.$langs->trans(
"Project").
'</td><td class="valuefieldcreate">';
1899 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');
1900 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>';
1907 print
'<tr class="field_incoterm_id">';
1908 print
'<td class="titlefieldcreate"><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $soc->label_incoterms, 1).
'</label></td>';
1909 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1910 print
$form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms :
''), (!empty($soc->location_incoterms) ? $soc->location_incoterms :
''));
1915 print
'<tr class="field_model">';
1916 print
'<td class="titlefieldcreate">'.$langs->trans(
"DefaultModel").
'</td>';
1917 print
'<td class="valuefieldcreate">';
1918 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1920 $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT :
getDolGlobalString(
"PROPALE_ADDON_PDF"));
1921 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1926 print
'<tr class="field_currency">';
1927 print
'<td class="titlefieldcreate">'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1928 print
'<td class="valuefieldcreate maxwidthonsmartphone">';
1929 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code,
'multicurrency_code', 0);
1934 print
'<tr class="field_note_public">';
1935 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1936 print
'<td class="valuefieldcreate">';
1937 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc) ? $objectsrc->note_public :
null));
1938 $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%');
1939 print $doleditor->Create(1);
1942 if (empty($user->socid)) {
1943 print
'<tr class="field_note_private">';
1944 print
'<td class="titlefieldcreate tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1945 print
'<td class="valuefieldcreate">';
1946 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private :
null));
1947 $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%');
1948 print $doleditor->Create(1);
1954 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
1957 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1959 if ($origin ==
'contrat') {
1961 $objectsrc->remise_absolue = $remise_absolue;
1962 $objectsrc->remise_percent = $remise_percent;
1963 $objectsrc->update_price(1,
'auto', 1);
1966 print
"\n<!-- ".$classname.
" info -->";
1968 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1969 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1970 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1971 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1972 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1974 $newclassname = $classname;
1975 if ($newclassname ==
'Propal') {
1976 $newclassname =
'CommercialProposal';
1977 } elseif ($newclassname ==
'Commande') {
1978 $newclassname =
'Order';
1979 } elseif ($newclassname ==
'Expedition') {
1980 $newclassname =
'Sending';
1981 } elseif ($newclassname ==
'Fichinter') {
1982 $newclassname =
'Intervention';
1985 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
1986 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).
'</td></tr>';
1987 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1988 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1989 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1992 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1993 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1995 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).
"</td></tr>";
1998 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1999 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2000 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2011 if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
2012 print
'<input type="hidden" name="createmode" value="empty">';
2015 if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
2016 print
'<br><table>';
2020 print
'<td><input type="radio" name="createmode" value="copy"></td>';
2021 print
'<td>'.$langs->trans(
"CopyPropalFrom").
' </td>';
2023 $liste_propal = array();
2024 $liste_propal [0] =
'';
2026 $sql =
"SELECT p.rowid as id, p.ref, s.nom";
2027 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal p";
2028 $sql .=
", ".MAIN_DB_PREFIX.
"societe s";
2029 $sql .=
" WHERE s.rowid = p.fk_soc";
2030 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
2031 $sql .=
" AND p.fk_statut <> 0";
2032 $sql .=
" ORDER BY Id";
2034 $resql = $db->query($sql);
2036 $num = $db->num_rows(
$resql);
2039 $row = $db->fetch_row(
$resql);
2040 $propalRefAndSocName = $row[1].
" - ".$row[2];
2041 $liste_propal[$row[0]] = $propalRefAndSocName;
2044 print
$form->selectarray(
"copie_propal", $liste_propal, 0);
2050 print
'<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
2051 print
'<td valign="top" colspan="2">'.$langs->trans(
"CreateEmptyPropal").
'</td></tr>';
2057 $langs->load(
"bills");
2059 print
$form->buttonsSaveCancel(
"CreateDraft");
2065 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2068 $title = $langs->trans(
'ProductsAndServices');
2071 print
'<div class="div-table-responsive-no-min">';
2072 print
'<table class="noborder centpercent">';
2074 $objectsrc->printOriginLinesList();
2079 } elseif ($object->id > 0) {
2085 $soc->fetch($object->socid);
2093 if ($action ==
'clone') {
2095 $formquestion = array(
2098 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')),
2099 array(
'type' =>
'checkbox',
'name' =>
'update_prices',
'label' => $langs->trans(
'PuttingPricesUpToDate'),
'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
2101 if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
2102 $formquestion[] = array(
'type' =>
'date',
'name' =>
'date_delivery',
'label' => $langs->trans(
"DeliveryDate"),
'value' => $object->delivery_date);
2105 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmClonePropal', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2108 if ($action ==
'closeas') {
2110 $formquestion = array();
2111 if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2112 $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)));
2114 $formquestion[] = array(
'type' =>
'text',
'name' =>
'note_private',
'label' => $langs->trans(
"Note"),
'value' =>
'');
2116 if (
getDolGlobalInt(
'PROPOSAL_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2121 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2123 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)) {
2124 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2126 $object->fetchObjectLinked();
2128 $eligibleForDepositGeneration =
true;
2130 if (array_key_exists(
'facture', $object->linkedObjects)) {
2131 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2133 $eligibleForDepositGeneration =
false;
2139 if ($eligibleForDepositGeneration && array_key_exists(
'commande', $object->linkedObjects)) {
2140 foreach ($object->linkedObjects[
'commande'] as $order) {
2141 $order->fetchObjectLinked();
2143 if (array_key_exists(
'facture', $order->linkedObjects)) {
2144 foreach ($order->linkedObjects[
'facture'] as $invoice) {
2146 $eligibleForDepositGeneration =
false;
2155 if ($eligibleForDepositGeneration) {
2156 $formquestion[] = array(
2157 'type' =>
'checkbox',
2158 'tdclass' =>
'showonlyifsigned',
2159 'name' =>
'generate_deposit',
2160 'morecss' =>
'margintoponly marginbottomonly',
2161 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2164 $formquestion[] = array(
2166 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2168 'label' => $langs->trans(
'DateInvoice'),
2173 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2174 $formquestion[] = array(
2176 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2177 'name' =>
'date_pointoftax',
2178 'label' => $langs->trans(
'DatePointOfTax'),
2184 $paymentTermsSelect =
$form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 1,
'minwidth200');
2186 $formquestion[] = array(
2188 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2189 'name' =>
'cond_reglement_id',
2190 'label' => $langs->trans(
'PaymentTerm'),
2191 'value' => $paymentTermsSelect
2194 $formquestion[] = array(
2195 'type' =>
'checkbox',
2196 'tdclass' =>
'showonlyifgeneratedeposit',
2197 'name' =>
'validate_generated_deposit',
2198 'morecss' =>
'margintoponly marginbottomonly',
2199 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2202 $formquestion[] = array(
2203 'type' =>
'onecolumn',
2206 let signedValue = ' . $object::STATUS_SIGNED .
';
2208 $(document).ready(function() {
2209 $("[name=generate_deposit]").change(function () {
2210 let $self = $(this);
2211 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2213 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2222 $("#statut").change(function() {
2223 let $target = $(".showonlyifsigned").parent(".tagtr");
2225 if ($(this).val() == signedValue) {
2231 $("[name=generate_deposit]").trigger("change");
2236 $("#statut").trigger("change");
2246 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2247 $notify =
new Notify($db);
2248 $formquestion = array_merge($formquestion, array(
2249 array(
'type' =>
'onecolumn',
'value' => $notify->confirmMessage(
'PROPAL_CLOSE_SIGNED', $object->socid, $object)),
2253 if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2254 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'SetAcceptedRefused'),
'',
'confirm_closeas', $formquestion,
'', 1, 250);
2256 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?statut=3&id=' . $object->id, $langs->trans(
'Close'),
'',
'confirm_closeas', $formquestion,
'', 1, 250);
2258 } elseif ($action ==
'delete') {
2260 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteProp'), $langs->trans(
'ConfirmDeleteProp', $object->ref),
'confirm_delete',
'', 0, 1);
2261 } elseif ($action ==
'reopen') {
2263 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ReOpen'), $langs->trans(
'ConfirmReOpenProp', $object->ref),
'confirm_reopen',
'', 0, 1);
2264 } elseif ($action ==
'ask_deleteline') {
2266 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2267 } elseif ($action ==
'validate') {
2272 $ref = substr($object->ref, 1, 4);
2273 if ($ref ==
'PROV' || $ref ==
'') {
2274 $numref = $object->getNextNumRef($soc);
2275 if (empty($numref)) {
2280 $numref = $object->ref;
2283 $text = $langs->trans(
'ConfirmValidateProp', $numref);
2285 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2286 $notify =
new Notify($db);
2288 $text .= $notify->confirmMessage(
'PROPAL_VALIDATE', $object->socid, $object);
2293 foreach ($object->lines as $line) {
2294 $res = $line->fetch_product();
2296 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2302 if ($nbMandated > 0) {
2303 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2307 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateProp'), $text,
'confirm_validate',
'', 0, 1);
2313 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2314 if (empty($reshook)) {
2316 } elseif ($reshook > 0) {
2326 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2328 $morehtmlref =
'<div class="refidno">';
2330 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2331 $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);
2333 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
2334 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2335 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/comm/propal/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherProposals").
'</a>)';
2339 $langs->load(
"projects");
2340 $morehtmlref .=
'<br>';
2341 if ($usercancreate) {
2342 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2343 if ($action !=
'classify') {
2344 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2346 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2348 if (!empty($object->fk_project)) {
2350 $proj->fetch($object->fk_project);
2351 $morehtmlref .= $proj->getNomUrl(1);
2353 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2358 $morehtmlref .=
'</div>';
2361 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2364 print
'<div class="fichecenter">';
2365 print
'<div class="fichehalfleft">';
2366 print
'<div class="underbanner clearboth"></div>';
2368 print
'<table class="border tableforfield centpercent">';
2371 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2372 $filterabsolutediscount =
"fk_facture_source IS NULL";
2373 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2375 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2376 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2379 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2381 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2382 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2383 $absolute_discount =
price2num($absolute_discount,
'MT');
2384 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2390 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2391 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2407 print
$form->editfieldkey(
"DatePropal",
'date',
'', $object, $editenable);
2408 print
'</td><td class="valuefield">';
2409 if ($action ==
'editdate' && $usercancreate && $caneditfield) {
2410 print
'<form name="editdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2411 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2412 print
'<input type="hidden" name="action" value="setdate">';
2413 print
$form->selectDate($object->date,
're',
'',
'', 0,
"editdate");
2414 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2417 if ($object->date) {
2428 print
'<table class="nobordernopadding centpercent"><tr><td>';
2429 print $langs->trans(
'DateEndPropal');
2431 if ($action !=
'editecheance' && $usercancreate && $caneditfield) {
2432 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>';
2434 print
'</tr></table>';
2435 print
'</td><td class="valuefield">';
2436 if ($action ==
'editecheance' && $usercancreate && $caneditfield) {
2437 print
'<form name="editecheance" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2438 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2439 print
'<input type="hidden" name="action" value="setecheance">';
2440 print
$form->selectDate($object->fin_validite,
'ech',
'',
'',
'',
"editecheance");
2441 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2444 if (!empty($object->fin_validite)) {
2446 if ($object->statut ==
Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) {
2458 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2459 print $langs->trans(
'PaymentConditionsShort');
2461 if ($action !=
'editconditions' && $usercancreate && $caneditfield) {
2462 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>';
2464 print
'</tr></table>';
2465 print
'</td><td class="valuefield">';
2466 if ($action ==
'editconditions' && $usercancreate && $caneditfield) {
2467 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 0,
'', 1, $object->deposit_percent);
2469 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 0,
'', 1, $object->deposit_percent);
2475 print
'<tr class="field_mode_reglement_id">';
2476 print
'<td class="titlefieldcreate">';
2477 print
'<table class="nobordernopadding centpercent"><tr><td>';
2478 print $langs->trans(
'PaymentMode');
2480 if ($action !=
'editmode' && $usercancreate && $caneditfield) {
2481 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>';
2483 print
'</tr></table>';
2484 print
'</td><td class="valuefieldcreate">';
2485 if ($action ==
'editmode' && $usercancreate && $caneditfield) {
2486 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2488 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2493 $langs->load(
'deliveries');
2495 print
$form->editfieldkey($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2496 print
'</td><td class="valuefieldedit">';
2497 print
$form->editfieldval($langs->trans(
'DeliveryDate'),
'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield,
'datepicker');
2502 print
'<tr class="fielddeliverydelay"><td>';
2503 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2505 print
$form->textwithpicto($langs->trans(
'AvailabilityPeriod'), $langs->trans(
'AvailabilityPeriod').
' ('.$langs->trans(
'AfterOrder').
')');
2507 print $langs->trans(
'AvailabilityPeriod');
2510 if ($action !=
'editavailability' && $usercancreate && $caneditfield) {
2511 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>';
2513 print
'</tr></table>';
2514 print
'</td><td class="valuefield">';
2515 if ($action ==
'editavailability' && $usercancreate && $caneditfield) {
2516 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2518 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2527 print
'<table class="nobordernopadding centpercent"><tr><td>';
2528 print $langs->trans(
'SendingMethod');
2530 if ($action !=
'editshippingmethod' && $usercancreate && $caneditfield) {
2531 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>';
2533 print
'</tr></table>';
2534 print
'</td><td class="valuefield">';
2535 if ($action ==
'editshippingmethod' && $usercancreate && $caneditfield) {
2536 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2538 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2545 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
2546 $langs->load(
'stocks');
2547 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2549 print
'<tr class="field_warehouse_id"><td class="titlefieldcreate">';
2550 $editenable = $usercancreate;
2551 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2552 print
'</td><td class="valuefieldcreate">';
2553 if ($action ==
'editwarehouse') {
2554 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2556 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2564 print
'<table class="nobordernopadding centpercent"><tr><td>';
2565 print $langs->trans(
'Source');
2567 if ($action !=
'editdemandreason' && $usercancreate) {
2568 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>';
2570 print
'</tr></table>';
2571 print
'</td><td class="valuefield">';
2572 if ($action ==
'editdemandreason' && $usercancreate) {
2573 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2575 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2585 print
'<table class="nobordernopadding" width="100%"><tr><td>';
2586 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2588 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) {
2589 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>';
2591 print
'</tr></table>';
2592 print
'</td><td class="valuefield">';
2593 if ($object->statut == $object::STATUS_DRAFT && $action ==
'editmulticurrencycode' && $usercancreate) {
2594 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2596 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2601 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2604 print
'<table class="nobordernopadding" width="100%"><tr>';
2606 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2608 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) {
2609 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>';
2611 print
'</tr></table>';
2612 print
'</td><td class="valuefield">';
2613 if ($object->statut == $object::STATUS_DRAFT && ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') && $usercancreate) {
2614 if ($action ==
'actualizemulticurrencyrate') {
2617 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2619 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2620 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2621 print
'<div class="inline-block"> ';
2622 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2630 if ($soc->outstanding_limit) {
2633 print $langs->trans(
'OutstandingBill');
2634 print
'</td><td class="valuefield">';
2635 $arrayoutstandingbills = $soc->getOutstandingBills();
2636 print ($arrayoutstandingbills[
'opened'] > $soc->outstanding_limit ?
img_warning() :
'');
2637 print
price($arrayoutstandingbills[
'opened']).
' / ';
2638 print
price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
2643 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) &&
isModEnabled(
"banque")) {
2646 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2647 print $langs->trans(
'BankAccount');
2649 if ($action !=
'editbankaccount' && $usercancreate) {
2650 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>';
2652 print
'</tr></table>';
2653 print
'</td><td class="valuefield">';
2654 if ($action ==
'editbankaccount') {
2655 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2657 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2663 $tmparray = $object->getTotalWeightVolume();
2664 $totalWeight = $tmparray[
'weight'];
2665 $totalVolume = $tmparray[
'volume'];
2667 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2668 print
'<td class="valuefield">';
2669 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);
2673 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2674 print
'<td class="valuefield">';
2675 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);
2682 print
'<table width="100%" class="nobordernopadding"><tr><td>';
2683 print $langs->trans(
'IncotermLabel');
2684 print
'<td><td class="right">';
2685 if ($action !=
'editincoterm' && $usercancreate && $caneditfield) {
2686 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/comm/propal/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2690 print
'</td></tr></table>';
2692 print
'<td class="valuefield">';
2693 if ($action ==
'editincoterm' && $usercancreate && $caneditfield) {
2694 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2696 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2702 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2707 print
'<div class="fichehalfright">';
2708 print
'<div class="underbanner clearboth"></div>';
2710 print
'<table class="border tableforfield centpercent">';
2712 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2714 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2715 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>';
2719 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2720 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>';
2724 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2725 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>';
2730 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2731 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2735 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
2736 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2740 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2741 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2742 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2745 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2746 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2747 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2752 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
2753 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 0, - 1, - 1, $conf->currency).
'</td>';
2763 $formmargin->displayMarginInfos($object);
2769 print
'<div class="clearboth"></div><br>';
2771 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2772 $blocname =
'contacts';
2773 $title = $langs->trans(
'ContactsAddresses');
2774 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2777 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2778 $blocname =
'notes';
2779 $title = $langs->trans(
'Notes');
2780 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2788 $result = $object->getLinesArray();
2792 global $inputalsopricewithtax;
2793 $inputalsopricewithtax = 1;
2795 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2796 <input type="hidden" name="token" value="' .
newToken().
'">
2797 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2798 <input type="hidden" name="mode" value="">
2799 <input type="hidden" name="page_y" value="">
2800 <input type="hidden" name="id" value="' . $object->id.
'">
2804 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2807 print
'<div class="div-table-responsive-no-min">';
2808 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2809 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2812 if (!empty($object->lines)) {
2813 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2818 if ($action !=
'editline') {
2820 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2821 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2822 if (empty($reshook))
2823 $object->formAddObjectLine(1, $mysoc, $soc);
2826 $reshook = $hookmanager->executeHooks(
'formEditObjectLine',
$parameters, $object, $action);
2830 if (!empty($object->lines) || ($object->statut ==
Propal::STATUS_DRAFT && $usercancreate && $action !=
'selectlines' && $action !=
'editline')) {
2844 if ($action !=
'presend') {
2845 print
'<div class="tabsAction">';
2848 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2850 if (empty($reshook)) {
2851 if ($action !=
'editline') {
2853 if (($object->statut ==
Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
2854 || ($object->statut ==
Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
2855 if ($usercanvalidate) {
2856 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>';
2858 print
'<a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
'Validate').
'</a>';
2868 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=modif&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
2873 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#reopen').
'"';
2874 print
'>'.$langs->trans(
'ReOpen').
'</a>';
2878 if (empty($user->socid)) {
2880 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'', $usercansend);
2886 if ($usercancreateorder) {
2887 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>';
2892 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
2894 if ($usercancreatepurchaseorder) {
2895 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>';
2902 if ($usercancreateintervention) {
2903 $langs->load(
"interventions");
2904 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>';
2910 $langs->load(
"contracts");
2912 if ($usercancreatecontract) {
2913 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>';
2919 if (
isModEnabled(
'facture') && $usercancreateinvoice) {
2920 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>';
2923 $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
2924 if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
2925 if ($usercanclose) {
2926 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'&socid='.$object->socid.
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2928 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2933 if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2936 if ($usercanclose) {
2937 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=closeas&token='.
newToken().(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#close').
'"';
2938 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2940 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'"';
2941 print
'>'.$langs->trans(
'SetAcceptedRefused').
'</a>';
2947 print
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&token='.newToken().
'&action=closeas&token='.
newToken() . (empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#close') .
'"';
2948 print
'>' . $langs->trans(
'SetRefusedAndClose') .
'</a>';
2953 if ($usercancreate) {
2954 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>';
2958 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $usercandelete);
2966 if (
GETPOST(
'modelselected')) {
2967 $action =
'presend';
2970 if ($action !=
'presend') {
2971 print
'<div class="fichecenter"><div class="fichehalfleft">';
2972 print
'<a name="builddoc"></a>';
2977 $filedir = $conf->propal->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2978 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2979 $genallowed = $usercanread;
2980 $delallowed = $usercancreate;
2982 print $formfile->showdocuments(
'propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'', 0,
'', $soc->default_lang,
'', $object);
2985 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'propal'));
2987 $compatibleImportElementsList =
false;
2989 $compatibleImportElementsList = array(
'commande',
'propal');
2991 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2994 $useonlinesignature = 1;
2997 print
'<br><!-- Link to sign -->';
2998 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2999 print showOnlineSignatureUrl(
'proposal', $object->ref).
'<br>';
3002 print
'</div><div class="fichehalfright">';
3005 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3007 $somethingshown =
$formactions->showactions($object,
'propal', $socid, 1);
3009 print
'</div></div>';
3013 $modelmail =
'propal_send';
3014 $defaulttopic =
'SendPropalRef';
3015 $diroutput = $conf->propal->multidir_output[$object->entity];
3016 $trackid =
'pro'.$object->id;
3018 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';