41 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
43 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/margin/lib/margins.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
64 public $element =
'propal';
69 public $table_element =
'propal';
74 public $table_element_line =
'propaldet';
79 public $fk_element =
'fk_propal';
84 public $picto =
'propal';
90 public $ismultientitymanaged = 1;
96 public $restrictiononfksoc = 1;
146 public $date_creation;
157 public $date_validation;
162 public $date_signature;
167 public $user_signature;
184 public $date_livraison;
189 public $delivery_date;
192 public $fin_validite;
194 public $user_author_id;
195 public $user_valid_id;
196 public $user_close_id;
214 public $cond_reglement_code;
215 public $cond_reglement_doc;
216 public $mode_reglement_code;
218 public $deposit_percent;
240 public $address_type;
243 public $availability_id;
244 public $availability_code;
246 public $duree_validite;
248 public $demand_reason_id;
249 public $demand_reason_code;
251 public $warehouse_id;
253 public $extraparams = array();
258 public $lines = array();
261 public $labelStatus = array();
262 public $labelStatusShort = array();
268 public $fk_multicurrency;
270 public $multicurrency_code;
271 public $multicurrency_tx;
272 public $multicurrency_total_ht;
273 public $multicurrency_total_tva;
274 public $multicurrency_total_ttc;
305 public $fields = array(
306 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
307 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>15,
'index'=>1),
308 'ref' =>array(
'type'=>
'varchar(30)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>20),
309 'ref_client' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefCustomer',
'enabled'=>1,
'visible'=>-1,
'position'=>22),
310 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>40),
311 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'position'=>23),
312 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label'=>
'Fk projet',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>24),
313 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
314 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
315 'datep' =>array(
'type'=>
'date',
'label'=>
'Date',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
316 'fin_validite' =>array(
'type'=>
'datetime',
'label'=>
'DateEnd',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
317 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
318 'date_cloture' =>array(
'type'=>
'datetime',
'label'=>
'DateClosing',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
319 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
320 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>85),
321 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
322 'fk_user_cloture' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user cloture',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
323 'price' =>array(
'type'=>
'double',
'label'=>
'Price',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
327 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>125,
'isameasure'=>1),
328 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'VAT',
'enabled'=>1,
'visible'=>-1,
'position'=>130,
'isameasure'=>1),
329 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'LocalTax1',
'enabled'=>1,
'visible'=>-1,
'position'=>135,
'isameasure'=>1),
330 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'LocalTax2',
'enabled'=>1,
'visible'=>-1,
'position'=>140,
'isameasure'=>1),
331 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>145,
'isameasure'=>1),
332 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'BankAccount',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>150),
333 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
334 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
335 'deposit_percent' =>array(
'type'=>
'varchar(63)',
'label'=>
'DepositPercent',
'enabled'=>1,
'visible'=>-1,
'position'=>161),
336 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
337 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>170),
338 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>175),
339 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'PDFTemplate',
'enabled'=>1,
'visible'=>0,
'position'=>180),
340 'date_livraison' =>array(
'type'=>
'date',
'label'=>
'DateDeliveryPlanned',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
341 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'ShippingMethod',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
342 'fk_warehouse' =>array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Fk warehouse',
'enabled'=>
'isModEnabled("stock")',
'visible'=>-1,
'position'=>191),
343 'fk_availability' =>array(
'type'=>
'integer',
'label'=>
'Availability',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
344 'fk_delivery_address' =>array(
'type'=>
'integer',
'label'=>
'DeliveryAddress',
'enabled'=>1,
'visible'=>0,
'position'=>200),
345 'fk_input_reason' =>array(
'type'=>
'integer',
'label'=>
'InputReason',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
346 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
347 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>
'$conf->incoterm->enabled',
'visible'=>-1,
'position'=>220),
348 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLabel',
'enabled'=>
'$conf->incoterm->enabled',
'visible'=>-1,
'position'=>225),
349 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'MulticurrencyID',
'enabled'=>1,
'visible'=>-1,
'position'=>230),
350 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'MulticurrencyCurrency',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>235),
351 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyRate',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>240,
'isameasure'=>1),
352 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountHT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>245,
'isameasure'=>1),
353 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountVAT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>250,
'isameasure'=>1),
354 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountTTC',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>255,
'isameasure'=>1),
355 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
356 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>500),
357 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
392 global $conf, $langs;
396 $this->socid = $socid;
397 $this->
id = $propalid;
399 $this->duree_validite =
getDolGlobalInt(
'PROPALE_VALIDITY_DURATION', 0);
418 global $conf, $mysoc;
424 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
425 if ($idproduct > 0) {
426 $prod =
new Product($this->db);
427 $prod->fetch($idproduct);
429 $productdesc = $prod->description;
433 if (empty($tva_tx)) {
438 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
439 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
442 if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) {
443 $price = $prod->multiprices[$this->thirdparty->price_level];
450 $line->fk_product = $idproduct;
451 $line->desc = $productdesc;
455 $line->vat_src_code = $vat_src_code;
456 $line->tva_tx = $tva_tx;
457 $line->fk_unit = $prod->fk_unit;
459 $line->info_bits = 1;
462 $this->lines[] = $line;
480 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
481 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
486 $result =
$remise->fetch($idremise);
490 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
491 $this->db->rollback();
497 $this->line->context = $this->context;
499 $line->fk_propal = $this->id;
500 $line->fk_remise_except =
$remise->id;
501 $line->desc =
$remise->description;
502 $line->vat_src_code =
$remise->vat_src_code;
503 $line->tva_tx =
$remise->tva_tx;
504 $line->subprice = -
$remise->amount_ht;
505 $line->fk_product = 0;
507 $line->remise_percent = 0;
509 $line->info_bits = 2;
512 $line->price = -
$remise->amount_ht;
514 $line->total_ht = -
$remise->amount_ht;
515 $line->total_tva = -
$remise->amount_tva;
516 $line->total_ttc = -
$remise->amount_ttc;
518 $result = $line->insert();
525 $this->db->rollback();
529 $this->error = $line->error;
530 $this->errors = $line->errors;
531 $this->db->rollback();
535 $this->db->rollback();
577 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0,
$remise_percent = 0.0, $price_base_type =
'HT', $pu_ttc = 0.0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label =
'', $date_start =
'', $date_end =
'', $array_options = 0, $fk_unit =
null, $origin =
'', $origin_id = 0, $pu_ht_devise = 0, $fk_remise_except = 0, $noupdateafterinsertline = 0)
579 global $mysoc, $conf, $langs;
581 dol_syslog(get_class($this).
"::addline propalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type, fk_remise_except=".$fk_remise_except);
583 if ($this->statut == self::STATUS_DRAFT) {
584 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
593 if (empty($info_bits)) {
599 if (empty($fk_parent_line) || $fk_parent_line < 0) {
606 $pu_ht_devise =
price2num($pu_ht_devise);
608 if (!preg_match(
'/\((.*)\)/', $txtva)) {
614 if ($price_base_type ==
'HT') {
625 if ($date_start && $date_end && $date_start > $date_end) {
626 $langs->load(
"errors");
627 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
633 $product_type = $type;
634 if (!empty($fk_product) && $fk_product > 0) {
635 $product =
new Product($this->db);
636 $result = $product->fetch($fk_product);
637 $product_type = $product->type;
639 if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL) && $product_type == 0 && $product->stock_reel < $qty) {
640 $langs->load(
"errors");
641 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref);
642 $this->db->rollback();
658 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
659 $vat_src_code = $reg[1];
660 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
663 $tabprice =
calcul_price_total($qty, $pu,
$remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
665 $total_ht = $tabprice[0];
666 $total_tva = $tabprice[1];
667 $total_ttc = $tabprice[2];
668 $total_localtax1 = $tabprice[9];
669 $total_localtax2 = $tabprice[10];
670 $pu_ht = $tabprice[3];
671 $pu_tva = $tabprice[4];
672 $pu_ttc = $tabprice[5];
675 $multicurrency_total_ht = $tabprice[16];
676 $multicurrency_total_tva = $tabprice[17];
677 $multicurrency_total_ttc = $tabprice[18];
678 $pu_ht_devise = $tabprice[19];
682 if ($ranktouse == -1) {
683 $rangmax = $this->
line_max($fk_parent_line);
684 $ranktouse = $rangmax + 1;
699 $this->line->context = $this->context;
701 $this->line->fk_propal = $this->id;
702 $this->line->label = $label;
703 $this->line->desc = $desc;
704 $this->line->qty = $qty;
706 $this->line->vat_src_code = $vat_src_code;
707 $this->line->tva_tx = $txtva;
708 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
709 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
710 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
711 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
712 $this->line->fk_product = $fk_product;
713 $this->line->product_type = $type;
714 $this->line->fk_remise_except = $fk_remise_except;
716 $this->line->subprice = $pu_ht;
717 $this->line->rang = $ranktouse;
718 $this->line->info_bits = $info_bits;
719 $this->line->total_ht = $total_ht;
720 $this->line->total_tva = $total_tva;
721 $this->line->total_localtax1 = $total_localtax1;
722 $this->line->total_localtax2 = $total_localtax2;
723 $this->line->total_ttc = $total_ttc;
724 $this->line->special_code = $special_code;
725 $this->line->fk_parent_line = $fk_parent_line;
726 $this->line->fk_unit = $fk_unit;
728 $this->line->date_start = $date_start;
729 $this->line->date_end = $date_end;
731 $this->line->fk_fournprice = $fk_fournprice;
732 $this->line->pa_ht = $pa_ht;
734 $this->line->origin_id = $origin_id;
735 $this->line->origin = $origin;
738 $this->line->fk_multicurrency = $this->fk_multicurrency;
739 $this->line->multicurrency_code = $this->multicurrency_code;
740 $this->line->multicurrency_subprice = $pu_ht_devise;
741 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
742 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
743 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
746 if (empty($qty) && empty($special_code)) {
747 $this->line->special_code = 3;
751 $this->line->price =
$price;
753 if (is_array($array_options) && count($array_options) > 0) {
754 $this->line->array_options = $array_options;
757 $result = $this->line->insert();
760 if (!empty($fk_parent_line)) {
762 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
763 $linecount = count($this->lines);
764 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
770 if (empty($noupdateafterinsertline)) {
776 return $this->line->id;
778 $this->error = $this->db->error();
779 $this->db->rollback();
783 $this->error = $this->line->error;
784 $this->errors = $this->line->errors;
785 $this->db->rollback();
789 dol_syslog(get_class($this).
"::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR);
824 public function updateline($rowid, $pu, $qty,
$remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $desc =
'', $price_base_type =
'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label =
'', $type = 0, $date_start =
'', $date_end =
'', $array_options = 0, $fk_unit =
null, $pu_ht_devise = 0, $notrigger = 0, $rang = 0)
826 global $mysoc, $langs;
828 dol_syslog(get_class($this).
"::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent,
829 txtva=$txtva, desc=$desc, price_base_type=$price_base_type, info_bits=$info_bits, special_code=$special_code, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, type=$type, date_start=$date_start, date_end=$date_end");
830 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
836 $pu_ht_devise =
price2num($pu_ht_devise);
837 if (!preg_match(
'/\((.*)\)/', $txtva)) {
843 if (empty($qty) && empty($special_code)) {
846 if (!empty($qty) && $special_code == 3) {
853 if ($date_start && $date_end && $date_start > $date_end) {
854 $langs->load(
"errors");
855 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
859 if ($this->statut == self::STATUS_DRAFT) {
872 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
873 $vat_src_code = $reg[1];
874 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
879 $tabprice =
calcul_price_total($qty, $pu,
$remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
880 $total_ht = $tabprice[0];
881 $total_tva = $tabprice[1];
882 $total_ttc = $tabprice[2];
883 $total_localtax1 = $tabprice[9];
884 $total_localtax2 = $tabprice[10];
885 $pu_ht = $tabprice[3];
886 $pu_tva = $tabprice[4];
887 $pu_ttc = $tabprice[5];
890 $multicurrency_total_ht = $tabprice[16];
891 $multicurrency_total_tva = $tabprice[17];
892 $multicurrency_total_ttc = $tabprice[18];
893 $pu_ht_devise = $tabprice[19];
905 $line->fetch($rowid);
907 $staticline = clone $line;
909 $line->oldline = $staticline;
911 $this->line->context = $this->context;
912 $this->line->rang = $rang;
915 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
916 $rangmax = $this->
line_max($fk_parent_line);
917 $this->line->rang = $rangmax + 1;
920 $this->line->id = $rowid;
921 $this->line->label = $label;
922 $this->line->desc = $desc;
923 $this->line->qty = $qty;
924 $this->line->product_type = $type;
925 $this->line->vat_src_code = $vat_src_code;
926 $this->line->tva_tx = $txtva;
927 $this->line->localtax1_tx = $txlocaltax1;
928 $this->line->localtax2_tx = $txlocaltax2;
929 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
930 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
932 $this->line->subprice = $pu_ht;
933 $this->line->info_bits = $info_bits;
935 $this->line->total_ht = $total_ht;
936 $this->line->total_tva = $total_tva;
937 $this->line->total_localtax1 = $total_localtax1;
938 $this->line->total_localtax2 = $total_localtax2;
939 $this->line->total_ttc = $total_ttc;
940 $this->line->special_code = $special_code;
941 $this->line->fk_parent_line = $fk_parent_line;
942 $this->line->skip_update_total = $skip_update_total;
943 $this->line->fk_unit = $fk_unit;
945 $this->line->fk_fournprice = $fk_fournprice;
946 $this->line->pa_ht = $pa_ht;
948 $this->line->date_start = $date_start;
949 $this->line->date_end = $date_end;
951 if (is_array($array_options) && count($array_options) > 0) {
953 foreach ($array_options as $key => $value) {
954 $this->line->array_options[$key] = $array_options[$key];
959 $this->line->multicurrency_subprice = $pu_ht_devise;
960 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
961 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
962 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
964 $result = $this->line->update($notrigger);
967 if (!empty($fk_parent_line)) {
973 $this->fk_propal = $this->id;
974 $this->
rowid = $rowid;
979 $this->error = $this->line->error;
980 $this->errors = $this->line->errors;
981 $this->db->rollback();
985 dol_syslog(get_class($this).
"::updateline Erreur -2 Propal en mode incompatible pour cette action");
1002 if ($this->statut == self::STATUS_DRAFT) {
1007 $line->context = $this->context;
1010 $line->fetch($lineid);
1012 if ($id > 0 && $line->fk_propal != $id) {
1013 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1018 $staticline = clone $line;
1019 $line->oldline = $staticline;
1021 if ($line->delete($user) > 0) {
1024 $this->db->commit();
1027 $this->error = $line->error;
1028 $this->errors = $line->errors;
1029 $this->db->rollback();
1033 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1047 public function create($user, $notrigger = 0)
1049 global $conf, $hookmanager, $mysoc;
1055 if (empty($this->date)) {
1058 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1059 if (empty($this->availability_id)) {
1060 $this->availability_id = 0;
1062 if (empty($this->demand_reason_id)) {
1063 $this->demand_reason_id = 0;
1067 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1072 if (empty($this->fk_multicurrency)) {
1073 $this->multicurrency_code = $conf->currency;
1074 $this->fk_multicurrency = 0;
1075 $this->multicurrency_tx = 1;
1079 $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
1086 $this->error =
"Failed to fetch company";
1087 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1092 if (!empty($this->
ref)) {
1095 $this->error =
'ErrorRefAlreadyExists';
1096 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1097 $this->db->rollback();
1102 if (empty($this->date)) {
1103 $this->error =
"Date of proposal is required";
1104 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1112 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"propal (";
1116 $sql .=
", remise_percent";
1117 $sql .=
", remise_absolue";
1118 $sql .=
", total_tva";
1119 $sql .=
", total_ttc";
1123 $sql .=
", fk_user_author";
1124 $sql .=
", note_private";
1125 $sql .=
", note_public";
1126 $sql .=
", model_pdf";
1127 $sql .=
", fin_validite";
1128 $sql .=
", fk_cond_reglement";
1129 $sql .=
", deposit_percent";
1130 $sql .=
", fk_mode_reglement";
1131 $sql .=
", fk_account";
1132 $sql .=
", ref_client";
1133 $sql .=
", ref_ext";
1134 $sql .=
", date_livraison";
1135 $sql .=
", fk_shipping_method";
1136 $sql .=
", fk_warehouse";
1137 $sql .=
", fk_availability";
1138 $sql .=
", fk_input_reason";
1139 $sql .=
", fk_projet";
1140 $sql .=
", fk_incoterms";
1141 $sql .=
", location_incoterms";
1143 $sql .=
", fk_multicurrency";
1144 $sql .=
", multicurrency_code";
1145 $sql .=
", multicurrency_tx";
1147 $sql .=
" VALUES (";
1148 $sql .= $this->socid;
1150 $sql .=
", ".((float) $this->remise);
1151 $sql .=
", ".($this->remise_percent ? ((
float) $this->remise_percent) :
'NULL');
1152 $sql .=
", ".($this->remise_absolue ? ((
float) $this->remise_absolue) :
'NULL');
1155 $sql .=
", '".$this->db->idate($this->date).
"'";
1156 $sql .=
", '".$this->db->idate($now).
"'";
1157 $sql .=
", '(PROV)'";
1158 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
1159 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1160 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1161 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1162 $sql .=
", ".($this->fin_validite !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
"NULL");
1163 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1164 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
'NULL');
1165 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1166 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1167 $sql .=
", '".$this->db->escape($this->ref_client).
"'";
1168 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
1169 $sql .=
", ".(empty($delivery_date) ?
"NULL" :
"'".$this->db->idate($delivery_date).
"'");
1170 $sql .=
", ".($this->shipping_method_id > 0 ? $this->shipping_method_id :
'NULL');
1171 $sql .=
", ".($this->warehouse_id > 0 ? $this->warehouse_id :
'NULL');
1172 $sql .=
", ".$this->availability_id;
1173 $sql .=
", ".$this->demand_reason_id;
1174 $sql .=
", ".($this->fk_project ? $this->fk_project :
"null");
1175 $sql .=
", ".(int) $this->fk_incoterms;
1176 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1177 $sql .=
", ".setEntity($this);
1178 $sql .=
", ".(int) $this->fk_multicurrency;
1179 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1180 $sql .=
", ".(double) $this->multicurrency_tx;
1183 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1184 $resql = $this->db->query(
$sql);
1186 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"propal");
1189 $this->
ref =
'(PROV'.$this->id.
')';
1190 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"propal SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1192 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1193 $resql = $this->db->query(
$sql);
1198 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1199 $this->linked_objects = $this->linkedObjectsIds;
1203 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1204 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1205 if (is_array($tmp_origin_id)) {
1206 foreach ($tmp_origin_id as $origin_id) {
1209 $this->error = $this->db->lasterror();
1215 $origin_id = $tmp_origin_id;
1218 $this->error = $this->db->lasterror();
1230 $fk_parent_line = 0;
1231 $num = count($this->lines);
1233 for ($i = 0; $i < $num; $i++) {
1234 if (!is_object($this->lines[$i])) {
1236 $line = (object) $this->lines[$i];
1238 $line = $this->lines[$i];
1241 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1242 $fk_parent_line = 0;
1245 $vatrate = $line->tva_tx;
1246 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', $vatrate)) {
1247 $vatrate .=
' ('.$line->vat_src_code.
')';
1250 if (!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) {
1251 $originid = $line->origin_id;
1252 $origintype = $line->origin;
1254 $originid = $line->id;
1255 $origintype = $this->element;
1263 $line->localtax1_tx,
1264 $line->localtax2_tx,
1266 $line->remise_percent,
1270 $line->product_type,
1272 $line->special_code,
1274 $line->fk_fournprice,
1279 $line->array_options,
1290 $this->error = $this->db->error;
1296 $line->id = $result;
1299 if ($result > 0 && $line->product_type == 9) {
1300 $fk_parent_line = $result;
1330 if (!$error && !$notrigger) {
1339 $this->error = $this->db->lasterror();
1344 $this->error = $this->db->lasterror();
1349 $this->db->commit();
1350 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1353 $this->db->rollback();
1357 $this->error = $this->db->lasterror();
1358 $this->db->rollback();
1373 public function createFromClone(
User $user, $socid = 0, $forceentity =
null, $update_prices =
false, $update_desc =
false)
1375 global $conf, $hookmanager, $mysoc;
1384 $object =
new self($this->db);
1389 $object->fetch($this->
id);
1391 $objsoc =
new Societe($this->db);
1394 if (!empty($socid) && $socid != $object->socid) {
1395 if ($objsoc->fetch($socid) > 0) {
1396 $object->socid = $objsoc->id;
1397 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1398 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
null);
1399 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1400 $object->fk_delivery_address =
'';
1412 $object->fk_project =
'';
1416 $object->ref_client =
'';
1420 $objsoc->fetch($object->socid);
1424 if ($update_prices ===
true || $update_desc ===
true) {
1425 if ($objsoc->id > 0 && !empty($object->lines)) {
1426 if ($update_prices ===
true && !empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1428 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1431 foreach ($object->lines as $line) {
1434 if ($line->fk_product > 0) {
1435 $prod =
new Product($this->db);
1436 $res = $prod->fetch($line->fk_product);
1438 if ($update_prices ===
true) {
1439 $pu_ht = $prod->price;
1443 if (!empty($conf->global->PRODUIT_MULTIPRICES) && $objsoc->price_level > 0) {
1444 $pu_ht = $prod->multiprices[$objsoc->price_level];
1445 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1446 if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) {
1447 $tva_tx = $prod->multiprices_tva_tx[$objsoc->price_level];
1450 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1452 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $objsoc->id);
1453 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1456 if (count($prodcustprice->lines) > 0) {
1457 $pu_ht =
price($prodcustprice->lines[0]->price);
1458 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1459 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1460 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1466 $line->subprice = $pu_ht;
1467 $line->tva_tx = $tva_tx;
1470 if ($update_desc ===
true) {
1471 $line->desc = $prod->description;
1481 $object->entity = (!empty($forceentity) ? $forceentity : $object->entity);
1485 $object->user_author = $user->id;
1486 $object->user_valid = 0;
1487 $object->date = $now;
1488 $object->datep = $now;
1489 $object->fin_validite = $object->date + ($object->duree_validite * 24 * 3600);
1490 if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) {
1491 $object->ref_client =
'';
1494 $object->note_private =
'';
1495 $object->note_public =
'';
1498 $object->context[
'createfromclone'] =
'createfromclone';
1499 $result = $object->create($user);
1501 $this->error = $object->error;
1502 $this->errors = array_merge($this->errors, $object->errors);
1508 if ($object->copy_linked_contact($this,
'internal') < 0) {
1515 if ($this->socid == $object->socid) {
1516 if ($object->copy_linked_contact($this,
'external') < 0) {
1524 if (is_object($hookmanager)) {
1525 $parameters = array(
'objFrom'=>$this,
'clonedObj'=>$object);
1527 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1535 unset($object->context[
'createfromclone']);
1539 $this->db->commit();
1542 $this->db->rollback();
1556 public function fetch($rowid, $ref =
'', $ref_ext =
'', $forceentity = 0)
1558 $sql =
"SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
1559 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1560 $sql .=
", p.datec";
1561 $sql .=
", p.date_signature as dates";
1562 $sql .=
", p.date_valid as datev";
1563 $sql .=
", p.datep as dp";
1564 $sql .=
", p.fin_validite as dfv";
1565 $sql .=
", p.date_livraison as delivery_date";
1566 $sql .=
", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
1567 $sql .=
", p.note_private, p.note_public";
1568 $sql .=
", p.fk_projet as fk_project, p.fk_statut";
1569 $sql .=
", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1570 $sql .=
", p.fk_delivery_address";
1571 $sql .=
", p.fk_availability";
1572 $sql .=
", p.fk_input_reason";
1573 $sql .=
", p.fk_cond_reglement";
1574 $sql .=
", p.fk_mode_reglement";
1575 $sql .=
', p.fk_account';
1576 $sql .=
", p.fk_shipping_method";
1577 $sql .=
", p.fk_warehouse";
1578 $sql .=
", p.fk_incoterms, p.location_incoterms";
1579 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1580 $sql .=
", p.tms as date_modification";
1581 $sql .=
", i.libelle as label_incoterms";
1582 $sql .=
", c.label as statut_label";
1583 $sql .=
", ca.code as availability_code, ca.label as availability";
1584 $sql .=
", dr.code as demand_reason_code, dr.label as demand_reason";
1585 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1586 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1587 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
1588 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_propalst as c ON p.fk_statut = c.id';
1589 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.
getEntity(
'c_paiement').
')';
1590 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN ('.
getEntity(
'c_payment_term').
')';
1591 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON p.fk_availability = ca.rowid';
1592 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
1593 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON p.fk_incoterms = i.rowid';
1596 if (!empty($forceentity)) {
1597 $sql .=
" WHERE p.entity = ".(int) $forceentity;
1599 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
1601 $sql .=
" AND p.ref='".$this->db->escape($ref).
"'";
1604 $sql .=
" WHERE p.rowid = ".((int) $rowid);
1607 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1608 $resql = $this->db->query(
$sql);
1610 if ($this->db->num_rows($resql)) {
1611 $obj = $this->db->fetch_object($resql);
1613 $this->
id = $obj->rowid;
1614 $this->entity = $obj->entity;
1616 $this->
ref = $obj->ref;
1617 $this->ref_client = $obj->ref_client;
1618 $this->ref_customer = $obj->ref_client;
1619 $this->ref_ext = $obj->ref_ext;
1621 $this->remise = $obj->remise;
1622 $this->remise_percent = $obj->remise_percent;
1623 $this->remise_absolue = $obj->remise_absolue;
1624 $this->total = $obj->total_ttc;
1625 $this->total_ttc = $obj->total_ttc;
1626 $this->total_ht = $obj->total_ht;
1627 $this->total_tva = $obj->total_tva;
1628 $this->total_localtax1 = $obj->localtax1;
1629 $this->total_localtax2 = $obj->localtax2;
1631 $this->socid = $obj->fk_soc;
1632 $this->thirdparty =
null;
1634 $this->fk_project = $obj->fk_project;
1635 $this->project =
null;
1637 $this->model_pdf = $obj->model_pdf;
1638 $this->modelpdf = $obj->model_pdf;
1639 $this->last_main_doc = $obj->last_main_doc;
1640 $this->note = $obj->note_private;
1641 $this->note_private = $obj->note_private;
1642 $this->note_public = $obj->note_public;
1644 $this->status = (int) $obj->fk_statut;
1645 $this->statut = $this->status;
1647 $this->datec = $this->db->jdate($obj->datec);
1648 $this->datev = $this->db->jdate($obj->datev);
1649 $this->date_creation = $this->db->jdate($obj->datec);
1650 $this->date_validation = $this->db->jdate($obj->datev);
1651 $this->date_modification = $this->db->jdate($obj->date_modification);
1652 $this->date_signature = $this->db->jdate($obj->dates);
1653 $this->date = $this->db->jdate($obj->dp);
1654 $this->datep = $this->db->jdate($obj->dp);
1655 $this->fin_validite = $this->db->jdate($obj->dfv);
1656 $this->date_livraison = $this->db->jdate($obj->delivery_date);
1657 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1658 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1659 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
1660 $this->availability_id = $obj->fk_availability;
1661 $this->availability_code = $obj->availability_code;
1663 $this->demand_reason_id = $obj->fk_input_reason;
1664 $this->demand_reason_code = $obj->demand_reason_code;
1666 $this->fk_address = $obj->fk_delivery_address;
1668 $this->mode_reglement_id = $obj->fk_mode_reglement;
1669 $this->mode_reglement_code = $obj->mode_reglement_code;
1670 $this->mode_reglement = $obj->mode_reglement;
1671 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1672 $this->cond_reglement_id = $obj->fk_cond_reglement;
1673 $this->cond_reglement_code = $obj->cond_reglement_code;
1674 $this->cond_reglement = $obj->cond_reglement;
1675 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1676 $this->deposit_percent = $obj->deposit_percent;
1678 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1680 $this->user_author_id = $obj->fk_user_author;
1681 $this->user_valid_id = $obj->fk_user_valid;
1682 $this->user_close_id = $obj->fk_user_cloture;
1685 $this->fk_incoterms = $obj->fk_incoterms;
1686 $this->location_incoterms = $obj->location_incoterms;
1687 $this->label_incoterms = $obj->label_incoterms;
1690 $this->fk_multicurrency = $obj->fk_multicurrency;
1691 $this->multicurrency_code = $obj->multicurrency_code;
1692 $this->multicurrency_tx = $obj->multicurrency_tx;
1693 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1694 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1695 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1697 if ($obj->fk_statut == self::STATUS_DRAFT) {
1698 $this->brouillon = 1;
1705 $this->db->free($resql);
1707 $this->lines = array();
1718 $this->error =
"Record Not Found";
1721 $this->error = $this->db->lasterror();
1740 if (isset($this->
ref)) {
1741 $this->
ref = trim($this->
ref);
1743 if (isset($this->ref_client)) {
1744 $this->ref_client = trim($this->ref_client);
1746 if (isset($this->note) || isset($this->note_private)) {
1747 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1749 if (isset($this->note_public)) {
1750 $this->note_public = trim($this->note_public);
1752 if (isset($this->model_pdf)) {
1753 $this->model_pdf = trim($this->model_pdf);
1755 if (isset($this->import_key)) {
1756 $this->import_key = trim($this->import_key);
1758 if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
1759 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1766 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET";
1767 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1768 $sql .=
" ref_client=".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
1769 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1770 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1771 $sql .=
" datep=".(strval($this->date) !=
'' ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1772 if (!empty($this->fin_validite)) {
1773 $sql .=
" fin_validite=".(strval($this->fin_validite) !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
'null').
",";
1775 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1776 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1777 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1778 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1779 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1780 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1781 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1782 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1783 $sql .=
" fk_user_valid=".(isset($this->user_valid) ? $this->user_valid :
"null").
",";
1784 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1785 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1786 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1787 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1788 $sql .=
" fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id :
"null").
",";
1789 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1790 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1791 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1792 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1793 $sql .=
" WHERE rowid=".((int) $this->
id);
1797 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1798 $resql = $this->db->query(
$sql);
1801 $this->errors[] =
"Error ".$this->db->lasterror();
1811 if (!$error && !$notrigger) {
1822 foreach ($this->errors as $errmsg) {
1823 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1824 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1826 $this->db->rollback();
1829 $this->db->commit();
1845 public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $filters =
'')
1848 global $langs, $conf;
1850 $this->lines = array();
1852 $sql =
'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,';
1853 $sql .=
' d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,';
1854 $sql .=
' d.fk_unit,';
1855 $sql .=
' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tobatch as product_tobatch, p.barcode as product_barcode,';
1856 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units,';
1857 $sql .=
' d.date_start, d.date_end,';
1858 $sql .=
' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc';
1859 $sql .=
' FROM '.MAIN_DB_PREFIX.
'propaldet as d';
1860 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (d.fk_product = p.rowid)';
1861 $sql .=
' WHERE d.fk_propal = '.((int) $this->
id);
1862 if ($only_product) {
1863 $sql .=
' AND p.fk_product_type = 0';
1868 $sql .=
' ORDER by d.rang';
1870 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1871 $result = $this->db->query(
$sql);
1873 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
1875 $num = $this->db->num_rows($result);
1879 $objp = $this->db->fetch_object($result);
1883 $line->rowid = $objp->rowid;
1884 $line->id = $objp->rowid;
1885 $line->fk_propal = $objp->fk_propal;
1886 $line->fk_parent_line = $objp->fk_parent_line;
1887 $line->product_type = $objp->product_type;
1888 $line->label = $objp->custom_label;
1889 $line->desc = $objp->description;
1890 $line->description = $objp->description;
1891 $line->qty = $objp->qty;
1892 $line->vat_src_code = $objp->vat_src_code;
1893 $line->tva_tx = $objp->tva_tx;
1894 $line->localtax1_tx = $objp->localtax1_tx;
1895 $line->localtax2_tx = $objp->localtax2_tx;
1896 $line->localtax1_type = $objp->localtax1_type;
1897 $line->localtax2_type = $objp->localtax2_type;
1898 $line->subprice = $objp->subprice;
1899 $line->fk_remise_except = $objp->fk_remise_except;
1900 $line->remise_percent = $objp->remise_percent;
1901 $line->price = $objp->price;
1903 $line->info_bits = $objp->info_bits;
1904 $line->total_ht = $objp->total_ht;
1905 $line->total_tva = $objp->total_tva;
1906 $line->total_localtax1 = $objp->total_localtax1;
1907 $line->total_localtax2 = $objp->total_localtax2;
1908 $line->total_ttc = $objp->total_ttc;
1909 $line->fk_fournprice = $objp->fk_fournprice;
1910 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1911 $line->pa_ht = $marginInfos[0];
1912 $line->marge_tx = $marginInfos[1];
1913 $line->marque_tx = $marginInfos[2];
1914 $line->special_code = $objp->special_code;
1915 $line->rang = $objp->rang;
1917 $line->fk_product = $objp->fk_product;
1919 $line->ref = $objp->product_ref;
1920 $line->libelle = $objp->product_label;
1922 $line->product_ref = $objp->product_ref;
1923 $line->product_label = $objp->product_label;
1924 $line->product_desc = $objp->product_desc;
1925 $line->product_tobatch = $objp->product_tobatch;
1926 $line->product_barcode = $objp->product_barcode;
1928 $line->fk_product_type = $objp->fk_product_type;
1929 $line->fk_unit = $objp->fk_unit;
1930 $line->weight = $objp->weight;
1931 $line->weight_units = $objp->weight_units;
1932 $line->volume = $objp->volume;
1933 $line->volume_units = $objp->volume_units;
1935 $line->date_start = $this->db->jdate($objp->date_start);
1936 $line->date_end = $this->db->jdate($objp->date_end);
1939 $line->fk_multicurrency = $objp->fk_multicurrency;
1940 $line->multicurrency_code = $objp->multicurrency_code;
1941 $line->multicurrency_subprice = $objp->multicurrency_subprice;
1942 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
1943 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
1944 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
1946 $line->fetch_optionals();
1949 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
1950 $tmpproduct =
new Product($this->db);
1951 $tmpproduct->fetch($objp->fk_product);
1952 $tmpproduct->getMultiLangs();
1954 $line->multilangs = $tmpproduct->multilangs;
1957 $this->lines[$i] = $line;
1962 $this->db->free($result);
1966 $this->error = $this->db->lasterror();
1978 public function valid($user, $notrigger = 0)
1982 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1987 if ($this->statut == self::STATUS_VALIDATED) {
1988 dol_syslog(get_class($this).
"::valid action abandonned: already validated", LOG_WARNING);
1992 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->creer))
1993 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)))) {
1994 $this->error =
'ErrorPermissionDenied';
1995 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
2004 $soc =
new Societe($this->db);
2005 $soc->fetch($this->socid);
2008 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
2015 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2016 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
2017 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
", date_valid='".$this->db->idate($now).
"', fk_user_valid=".((int) $user->id);
2020 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
2021 $resql = $this->db->query(
$sql);
2028 if (!$error && !$notrigger) {
2030 $result = $this->
call_trigger(
'PROPAL_VALIDATE', $user);
2038 $this->oldref = $this->ref;
2041 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
2043 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'propale/".$this->db->escape($this->newref).
"'";
2044 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
2045 $resql = $this->db->query(
$sql);
2048 $this->error = $this->db->lasterror();
2054 $dirsource = $conf->propal->multidir_output[$this->entity].
'/'.$oldref;
2055 $dirdest = $conf->propal->multidir_output[$this->entity].
'/'.$newref;
2056 if (!$error && file_exists($dirsource)) {
2057 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
2058 if (@rename($dirsource, $dirdest)) {
2061 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
2062 foreach ($listoffiles as $fileentry) {
2063 $dirsource = $fileentry[
'name'];
2064 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
2065 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
2066 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
2067 @rename($dirsource, $dirdest);
2074 $this->brouillon = 0;
2076 $this->user_valid_id = $user->id;
2077 $this->datev = $now;
2079 $this->db->commit();
2082 $this->db->rollback();
2101 $this->error =
'ErrorBadParameter';
2102 dol_syslog(get_class($this).
"::set_date ".$this->error, LOG_ERR);
2106 if (!empty($user->rights->propal->creer)) {
2111 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET datep = '".$this->db->idate($date).
"'";
2112 $sql .=
" WHERE rowid = ".((int) $this->
id);
2115 $resql = $this->db->query(
$sql);
2117 $this->errors[] = $this->db->error();
2122 $this->oldcopy = clone $this;
2123 $this->date = $date;
2124 $this->datep = $date;
2127 if (!$notrigger && empty($error)) {
2137 $this->db->commit();
2140 foreach ($this->errors as $errmsg) {
2141 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2142 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2144 $this->db->rollback();
2164 if (!empty($user->rights->propal->creer)) {
2169 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET fin_validite = ".($date_end_validity !=
'' ?
"'".$this->db->idate($date_end_validity).
"'" :
'null');
2170 $sql .=
" WHERE rowid = ".((int) $this->
id);
2174 $resql = $this->db->query(
$sql);
2176 $this->errors[] = $this->db->error();
2182 $this->oldcopy = clone $this;
2183 $this->fin_validite = $date_end_validity;
2186 if (!$notrigger && empty($error)) {
2196 $this->db->commit();
2199 foreach ($this->errors as $errmsg) {
2200 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2201 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2203 $this->db->rollback();
2237 if (!empty($user->rights->propal->creer)) {
2242 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal ";
2243 $sql .=
" SET date_livraison = ".($delivery_date !=
'' ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2244 $sql .=
" WHERE rowid = ".((int) $this->
id);
2247 $resql = $this->db->query(
$sql);
2249 $this->errors[] = $this->db->error();
2254 $this->oldcopy = clone $this;
2255 $this->date_livraison = $delivery_date;
2256 $this->delivery_date = $delivery_date;
2259 if (!$notrigger && empty($error)) {
2269 $this->db->commit();
2272 foreach ($this->errors as $errmsg) {
2273 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2274 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2276 $this->db->rollback();
2296 if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) {
2301 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2302 $sql .=
" SET fk_availability = ".((int) $id);
2303 $sql .=
" WHERE rowid = ".((int) $this->
id);
2305 dol_syslog(__METHOD__.
' availability('.$id.
')', LOG_DEBUG);
2306 $resql = $this->db->query(
$sql);
2308 $this->errors[] = $this->db->error();
2313 $this->oldcopy = clone $this;
2314 $this->fk_availability = $id;
2315 $this->availability_id = $id;
2318 if (!$notrigger && empty($error)) {
2328 $this->db->commit();
2331 foreach ($this->errors as $errmsg) {
2332 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2333 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2335 $this->db->rollback();
2339 $error_str =
'Propal status do not meet requirement '.$this->statut;
2341 $this->error = $error_str;
2342 $this->errors[] = $this->error;
2359 if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) {
2364 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal ";
2365 $sql .=
" SET fk_input_reason = ".((int) $id);
2366 $sql .=
" WHERE rowid = ".((int) $this->
id);
2369 $resql = $this->db->query(
$sql);
2371 $this->errors[] = $this->db->error();
2377 $this->oldcopy = clone $this;
2378 $this->fk_input_reason = $id;
2379 $this->demand_reason_id = $id;
2383 if (!$notrigger && empty($error)) {
2393 $this->db->commit();
2396 foreach ($this->errors as $errmsg) {
2397 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2398 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2400 $this->db->rollback();
2404 $error_str =
'Propal status do not meet requirement '.$this->statut;
2406 $this->error = $error_str;
2407 $this->errors[] = $this->error;
2424 if (!empty($user->rights->propal->creer)) {
2429 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
2430 $sql .=
" WHERE rowid = ".((int) $this->
id);
2432 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
2433 $resql = $this->db->query(
$sql);
2435 $this->errors[] = $this->db->error();
2440 $this->oldcopy = clone $this;
2441 $this->ref_client = $ref_client;
2444 if (!$notrigger && empty($error)) {
2454 $this->db->commit();
2457 foreach ($this->errors as $errmsg) {
2458 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2459 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2461 $this->db->rollback();
2484 if (!empty($user->rights->propal->creer)) {
2491 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET remise_percent = ".((
float)
$remise);
2495 $resql = $this->db->query(
$sql);
2497 $this->errors[] = $this->db->error();
2502 $this->oldcopy = clone $this;
2503 $this->remise_percent =
$remise;
2507 if (!$notrigger && empty($error)) {
2517 $this->db->commit();
2520 foreach ($this->errors as $errmsg) {
2521 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2522 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2524 $this->db->rollback();
2550 if (!empty($user->rights->propal->creer)) {
2555 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2556 $sql .=
" SET remise_absolue = ".((float)
$remise);
2560 $resql = $this->db->query(
$sql);
2562 $this->errors[] = $this->db->error();
2567 $this->oldcopy = clone $this;
2571 if (!$notrigger && empty($error)) {
2581 $this->db->commit();
2584 foreach ($this->errors as $errmsg) {
2585 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2586 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2588 $this->db->rollback();
2611 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2612 $sql .=
" SET fk_statut = ".((int) $status).
",";
2613 if (!empty(
$note)) {
2614 $sql .=
" note_private = '".$this->db->escape(
$note).
"',";
2616 $sql .=
" date_cloture=NULL, fk_user_cloture=NULL";
2617 $sql .=
" WHERE rowid = ".((int) $this->
id);
2621 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
2622 $resql = $this->db->query(
$sql);
2625 $this->errors[] =
"Error ".$this->db->lasterror();
2640 if (!empty($this->errors)) {
2641 foreach ($this->errors as $errmsg) {
2642 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2643 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2646 $this->db->rollback();
2649 $this->statut = $status;
2650 $this->status = $status;
2652 $this->db->commit();
2668 global $langs,$conf;
2677 if (empty($conf->global->PROPALE_KEEP_OLD_SIGNATURE_INFO)) {
2678 $date_signature = $now;
2679 $fk_user_signature = $user->id;
2681 $this->
info($this->
id);
2682 if (!isset($this->date_signature) || $this->date_signature ==
'') {
2683 $date_signature = $now;
2684 $fk_user_signature = $user->id;
2686 $date_signature = $this->date_signature;
2687 $fk_user_signature = $this->user_signature->id;
2691 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2692 $sql .=
" SET fk_statut = ".((int) $status).
", note_private = '".$this->db->escape($newprivatenote).
"', date_signature='".$this->db->idate($date_signature).
"', fk_user_signature=".$fk_user_signature;
2693 $sql .=
" WHERE rowid = ".((int) $this->
id);
2695 $resql = $this->db->query(
$sql);
2698 $modelpdf = !empty($conf->global->PROPALE_ADDON_PDF_ODT_CLOSED) ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
2699 $trigger_name =
'PROPAL_CLOSE_REFUSED';
2701 if ($status == self::STATUS_SIGNED) {
2702 $trigger_name =
'PROPAL_CLOSE_SIGNED';
2703 $modelpdf = !empty($conf->global->PROPALE_ADDON_PDF_ODT_TOBILL) ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->model_pdf;
2707 $soc->id = $this->socid;
2708 $result = $soc->set_as_client();
2711 $this->error=$this->db->lasterror();
2712 $this->db->rollback();
2717 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2719 $outputlangs = $langs;
2721 $outputlangs =
new Translate(
"", $conf);
2722 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2723 $outputlangs->setDefaultLang($newlang);
2727 $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
2728 $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
2729 $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
2732 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2736 $this->oldcopy= clone $this;
2737 $this->statut = $status;
2738 $this->status = $status;
2739 $this->date_signature = $date_signature;
2740 $this->note_private = $newprivatenote;
2743 if (!$notrigger && empty($error)) {
2753 $this->db->commit();
2756 $this->statut = $this->oldcopy->statut;
2757 $this->status = $this->oldcopy->statut;
2758 $this->date_signature = $this->oldcopy->date_signature;
2759 $this->note_private = $this->oldcopy->note_private;
2761 $this->db->rollback();
2765 $this->error = $this->db->lasterror();
2766 $this->db->rollback();
2781 global $conf, $langs;
2788 $triggerName =
'PROPAL_CLASSIFY_BILLED';
2794 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal SET fk_statut = '.self::STATUS_BILLED.
", ";
2795 $sql .=
" note_private = '".$this->db->escape($newprivatenote).
"', date_cloture='".$this->db->idate($now).
"', fk_user_cloture=".((int) $user->id);
2796 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_SIGNED);
2799 $resql = $this->db->query(
$sql);
2801 $this->errors[] = $this->db->error();
2804 $num = $this->db->affected_rows($resql);
2808 $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
2810 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2812 $outputlangs = $langs;
2814 $outputlangs =
new Translate(
"", $conf);
2815 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2816 $outputlangs->setDefaultLang($newlang);
2820 $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
2821 $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
2822 $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
2825 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2828 $this->oldcopy = clone $this;
2830 $this->date_cloture = $now;
2831 $this->note_private = $newprivatenote;
2834 if (!$notrigger && empty($error)) {
2844 $this->db->commit();
2847 foreach ($this->errors as $errmsg) {
2848 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2849 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2851 $this->db->rollback();
2870 if ($this->statut <= self::STATUS_DRAFT) {
2874 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
2878 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2879 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2880 $sql .=
", online_sign_ip = NULL , online_sign_name = NULL";
2881 $sql .=
" WHERE rowid = ".((int) $this->
id);
2883 $resql = $this->db->query(
$sql);
2885 $this->errors[] = $this->db->error();
2890 $this->oldcopy = clone $this;
2893 if (!$notrigger && empty($error)) {
2904 $this->brouillon = 1;
2906 $this->db->commit();
2909 foreach ($this->errors as $errmsg) {
2910 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2911 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2913 $this->db->rollback();
2933 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datep', $sortorder =
'DESC')
2940 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
2941 $sql .=
" p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
2942 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
2943 if (empty($user->rights->societe->client->voir) && !$socid) {
2944 $sql .=
", sc.fk_soc, sc.fk_user";
2946 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"propal as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
2947 if (empty($user->rights->societe->client->voir) && !$socid) {
2948 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
2950 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
2951 $sql .=
" AND p.fk_soc = s.rowid";
2952 $sql .=
" AND p.fk_statut = c.id";
2953 if (empty($user->rights->societe->client->voir) && !$socid) {
2954 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2957 $sql .=
" AND s.rowid = ".((int) $socid);
2960 $sql .=
" AND p.fk_statut = ".self::STATUS_DRAFT;
2962 if ($notcurrentuser > 0) {
2963 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
2965 $sql .= $this->db->order($sortfield, $sortorder);
2966 $sql .= $this->db->plimit($limit, $offset);
2968 $result = $this->db->query(
$sql);
2970 $num = $this->db->num_rows($result);
2974 $obj = $this->db->fetch_object($result);
2976 if ($shortlist == 1) {
2977 $ga[$obj->propalid] = $obj->ref;
2978 } elseif ($shortlist == 2) {
2979 $ga[$obj->propalid] = $obj->ref.
' ('.$obj->name.
')';
2981 $ga[$i][
'id'] = $obj->propalid;
2982 $ga[$i][
'ref'] = $obj->ref;
2983 $ga[$i][
'name'] = $obj->name;
3017 $linkedInvoices = array();
3020 foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
3023 foreach ($objectid as $key => $object) {
3025 if ($objecttype ==
'facture') {
3026 $linkedInvoices[] = $object;
3030 foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
3031 foreach ($subobjectid as $subkey => $subobject) {
3032 if ($subobjecttype ==
'facture') {
3033 $linkedInvoices[] = $subobject;
3041 if (count($linkedInvoices) > 0) {
3042 $sql =
"SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye";
3043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
3044 $sql .=
" WHERE rowid IN (".$this->db->sanitize(implode(
',', $linkedInvoices)).
")";
3046 dol_syslog(get_class($this).
"::InvoiceArrayList", LOG_DEBUG);
3047 $resql = $this->db->query(
$sql);
3050 $tab_sqlobj = array();
3051 $nump = $this->db->num_rows($resql);
3052 for ($i = 0; $i < $nump; $i++) {
3053 $sqlobj = $this->db->fetch_object($resql);
3054 $tab_sqlobj[] = $sqlobj;
3056 $this->db->free($resql);
3058 $nump = count($tab_sqlobj);
3062 while ($i < $nump) {
3063 $obj = array_shift($tab_sqlobj);
3086 public function delete($user, $notrigger = 0)
3089 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3105 if (!$error && !empty($this->table_element_line)) {
3106 $tabletodelete = $this->table_element_line;
3107 $sqlef =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
"_extrafields WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id).
")";
3108 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3109 if (!$this->db->query($sqlef) || !$this->db->query(
$sql)) {
3111 $this->error = $this->db->lasterror();
3112 $this->errors[] = $this->error;
3113 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3138 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3144 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3145 $res = $this->db->query(
$sql);
3148 $this->error = $this->db->lasterror();
3149 $this->errors[] = $this->error;
3150 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3165 if ($conf->propal->multidir_output[$this->entity] && !empty($this->
ref)) {
3166 $dir = $conf->propal->multidir_output[$this->entity].
"/".$ref;
3167 $file = $dir.
"/".$ref.
".pdf";
3168 if (file_exists($file)) {
3172 $this->error =
'ErrorFailToDeleteFile';
3173 $this->errors[] = $this->error;
3174 $this->db->rollback();
3178 if (file_exists($dir)) {
3181 $this->error =
'ErrorFailToDeleteDir';
3182 $this->errors[] = $this->error;
3183 $this->db->rollback();
3191 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3192 $this->db->commit();
3195 $this->db->rollback();
3212 if ($this->statut >= self::STATUS_DRAFT) {
3217 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal';
3218 $sql .=
' SET fk_availability = '.((int) $availability_id);
3219 $sql .=
' WHERE rowid='.((int) $this->
id);
3221 dol_syslog(__METHOD__.
' availability('.$availability_id.
')', LOG_DEBUG);
3222 $resql = $this->db->query(
$sql);
3224 $this->errors[] = $this->db->error();
3229 $this->oldcopy = clone $this;
3230 $this->availability_id = $availability_id;
3233 if (!$notrigger && empty($error)) {
3243 $this->db->commit();
3246 foreach ($this->errors as $errmsg) {
3247 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3248 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3250 $this->db->rollback();
3254 $error_str =
'Propal status do not meet requirement '.$this->statut;
3256 $this->error = $error_str;
3257 $this->errors[] = $this->error;
3276 if ($this->statut >= self::STATUS_DRAFT) {
3281 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal';
3282 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
3283 $sql .=
' WHERE rowid='.((int) $this->
id);
3285 dol_syslog(__METHOD__.
' demand_reason('.$demand_reason_id.
')', LOG_DEBUG);
3286 $resql = $this->db->query(
$sql);
3288 $this->errors[] = $this->db->error();
3293 $this->oldcopy = clone $this;
3294 $this->demand_reason_id = $demand_reason_id;
3297 if (!$notrigger && empty($error)) {
3307 $this->db->commit();
3310 foreach ($this->errors as $errmsg) {
3311 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3312 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3314 $this->db->rollback();
3318 $error_str =
'Propal status do not meet requirement '.$this->statut;
3320 $this->error = $error_str;
3321 $this->errors[] = $this->error;
3335 $sql =
"SELECT c.rowid, ";
3336 $sql .=
" c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,";
3337 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
3338 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as c";
3339 $sql .=
" WHERE c.rowid = ".((int) $id);
3341 $result = $this->db->query(
$sql);
3344 if ($this->db->num_rows($result)) {
3345 $obj = $this->db->fetch_object($result);
3347 $this->
id = $obj->rowid;
3349 $this->date_creation = $this->db->jdate($obj->datec);
3350 $this->date_validation = $this->db->jdate($obj->datev);
3351 $this->date_signature = $this->db->jdate($obj->date_signature);
3352 $this->date_cloture = $this->db->jdate($obj->date_cloture);
3354 $cuser =
new User($this->db);
3355 $cuser->fetch($obj->fk_user_author);
3356 $this->user_creation = $cuser;
3358 if ($obj->fk_user_valid) {
3359 $vuser =
new User($this->db);
3360 $vuser->fetch($obj->fk_user_valid);
3361 $this->user_validation = $vuser;
3364 if ($obj->fk_user_signature) {
3365 $user_signature =
new User($this->db);
3366 $user_signature->fetch($obj->fk_user_signature);
3367 $this->user_signature = $user_signature;
3370 if ($obj->fk_user_cloture) {
3371 $cluser =
new User($this->db);
3372 $cluser->fetch($obj->fk_user_cloture);
3373 $this->user_cloture = $cluser;
3376 $this->db->free($result);
3391 return $this->
LibStatut($this->statut, $mode);
3405 global $conf, $hookmanager;
3408 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3410 $langs->load(
"propal");
3411 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraft");
3412 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidated");
3413 $this->labelStatus[2] = $langs->transnoentitiesnoconv(
"PropalStatusSigned");
3414 $this->labelStatus[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSigned");
3415 $this->labelStatus[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilled");
3416 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraftShort");
3417 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidatedShort");
3418 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv(
"PropalStatusSignedShort");
3419 $this->labelStatusShort[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSignedShort");
3420 $this->labelStatusShort[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilledShort");
3424 if ($status == self::STATUS_DRAFT) {
3425 $statusType =
'status0';
3426 } elseif ($status == self::STATUS_VALIDATED) {
3427 $statusType =
'status1';
3428 } elseif ($status == self::STATUS_SIGNED) {
3429 $statusType =
'status4';
3430 } elseif ($status == self::STATUS_NOTSIGNED) {
3431 $statusType =
'status9';
3432 } elseif ($status == self::STATUS_BILLED) {
3433 $statusType =
'status6';
3437 $parameters = array(
'status' => $status,
'mode' => $mode);
3438 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3441 return $hookmanager->resPrint;
3444 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3459 global $conf, $langs;
3463 $sql =
"SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
3464 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3465 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3466 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
3467 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3471 if ($mode ==
'opened') {
3472 $sql .=
" AND p.fk_statut = ".self::STATUS_VALIDATED;
3474 if ($mode ==
'signed') {
3475 $sql .=
" AND p.fk_statut = ".self::STATUS_SIGNED;
3478 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3481 $resql = $this->db->query(
$sql);
3483 $langs->load(
"propal");
3488 $label = $labelShort =
'';
3489 if ($mode ==
'opened') {
3490 $delay_warning = $conf->propal->cloture->warning_delay;
3492 $label = $langs->transnoentitiesnoconv(
"PropalsToClose");
3493 $labelShort = $langs->transnoentitiesnoconv(
"ToAcceptRefuse");
3495 if ($mode ==
'signed') {
3496 $delay_warning = $conf->propal->facturation->warning_delay;
3498 $label = $langs->trans(
"PropalsToBill");
3499 $labelShort = $langs->trans(
"ToBill");
3503 $response->warning_delay = $delay_warning / 60 / 60 / 24;
3504 $response->label = $label;
3505 $response->labelShort = $labelShort;
3506 $response->url = DOL_URL_ROOT.
'/comm/propal/list.php?search_status='.$status.
'&mainmenu=commercial&leftmenu=propals';
3507 $response->url_late = DOL_URL_ROOT.
'/comm/propal/list.php?search_status='.$status.
'&mainmenu=commercial&leftmenu=propals&sortfield=p.datep&sortorder=asc';
3511 while ($obj = $this->db->fetch_object($resql)) {
3512 $response->nbtodo++;
3513 $response->total += $obj->total_ht;
3515 if ($mode ==
'opened') {
3516 $datelimit = $this->db->jdate($obj->datefin);
3517 if ($datelimit < ($now - $delay_warning)) {
3518 $response->nbtodolate++;
3527 $this->error = $this->db->error();
3542 global $conf, $langs;
3547 $sql =
"SELECT rowid";
3548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3549 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3550 $sql .= $this->db->plimit(100);
3552 $resql = $this->db->query(
$sql);
3554 $num_prods = $this->db->num_rows($resql);
3556 while ($i < $num_prods) {
3558 $row = $this->db->fetch_row($resql);
3559 $prodids[$i] = $row[0];
3565 $this->
ref =
'SPECIMEN';
3566 $this->ref_client =
'NEMICEPS';
3567 $this->specimen = 1;
3569 $this->date = time();
3570 $this->fin_validite = $this->date + 3600 * 24 * 30;
3571 $this->cond_reglement_id = 1;
3572 $this->cond_reglement_code =
'RECEP';
3573 $this->mode_reglement_id = 7;
3574 $this->mode_reglement_code =
'CHQ';
3575 $this->availability_id = 1;
3576 $this->availability_code =
'AV_NOW';
3577 $this->demand_reason_id = 1;
3578 $this->demand_reason_code =
'SRC_00';
3579 $this->note_public =
'This is a comment (public)';
3580 $this->note_private =
'This is a comment (private)';
3582 $this->multicurrency_tx = 1;
3583 $this->multicurrency_code = $conf->currency;
3588 while ($xnbp < $nbp) {
3590 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3592 $line->subprice = 100;
3595 $line->localtax1_tx = 0;
3596 $line->localtax2_tx = 0;
3598 $line->total_ht = 50;
3599 $line->total_ttc = 60;
3600 $line->total_tva = 10;
3601 $line->remise_percent = 50;
3603 $line->total_ht = 100;
3604 $line->total_ttc = 120;
3605 $line->total_tva = 20;
3606 $line->remise_percent = 00;
3609 if ($num_prods > 0) {
3610 $prodid = mt_rand(1, $num_prods);
3611 $line->fk_product = $prodids[$prodid];
3612 $line->product_ref =
'SPECIMEN';
3615 $this->lines[$xnbp] = $line;
3617 $this->total_ht += $line->total_ht;
3618 $this->total_tva += $line->total_tva;
3619 $this->total_ttc += $line->total_ttc;
3636 $this->nb = array();
3639 $sql =
"SELECT count(p.rowid) as nb";
3640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3641 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3642 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3643 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3644 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3647 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'propal').
")";
3649 $resql = $this->db->query(
$sql);
3652 while ($obj = $this->db->fetch_object($resql)) {
3653 $this->nb[
"proposals"] = $obj->nb;
3655 $this->db->free($resql);
3659 $this->error = $this->db->error();
3674 global $conf, $langs;
3675 $langs->load(
"propal");
3677 $classname = $conf->global->PROPALE_ADDON;
3679 if (!empty($classname)) {
3682 $file = $classname.
".php";
3685 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
3686 foreach ($dirmodels as $reldir) {
3690 $mybool |= @include_once $dir.$file;
3698 $obj =
new $classname();
3700 $numref = $obj->getNextValue($soc, $this);
3702 if ($numref !=
"") {
3705 $this->error = $obj->error;
3710 $langs->load(
"errors");
3711 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Proposal"));
3724 global $conf, $langs, $user;
3726 $langs->load(
'propal');
3728 $nofetch = !empty($params[
'nofetch']);
3730 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
3731 return [
'optimize' => $langs->trans(
"Proposal")];
3733 if ($user->hasRight(
'propal',
'lire')) {
3734 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Proposal").
'</u>';
3735 if (isset($this->statut)) {
3736 $datas[
'status'] =
' '.$this->getLibStatut(5);
3738 if (!empty($this->
ref)) {
3739 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3742 $langs->load(
'companies');
3743 if (empty($this->thirdparty)) {
3746 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
3748 if (!empty($this->ref_client)) {
3749 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$this->ref_client;
3752 $langs->load(
'project');
3753 if (empty($this->project)) {
3756 $datas[
'project'] =
'<br><b>'.$langs->trans(
'Project').
':</b> '.$this->project->getNomUrl(1,
'', 0, 1);
3760 if (!empty($this->total_ht)) {
3761 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
3763 if (!empty($this->total_tva)) {
3764 $datas[
'vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
3766 if (!empty($this->total_ttc)) {
3767 $datas[
'amountttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
3769 if (!empty($this->date)) {
3770 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
3772 if (!empty($this->delivery_date)) {
3773 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3791 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1)
3793 global $langs, $conf, $user, $hookmanager;
3795 if (!empty($conf->dol_no_mouse_hover)) {
3802 'objecttype' => $this->element,
3803 'option' => $option,
3806 $classfortooltip =
'classfortooltip';
3809 $classfortooltip =
'classforajaxtooltip';
3810 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3817 if ($user->hasRight(
'propal',
'lire')) {
3818 if ($option ==
'') {
3819 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3820 } elseif ($option ==
'compta') {
3821 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3822 } elseif ($option ==
'expedition') {
3823 $url = DOL_URL_ROOT.
'/expedition/propal.php?id='.$this->
id.$get_params;
3824 } elseif ($option ==
'document') {
3825 $url = DOL_URL_ROOT.
'/comm/propal/document.php?id='.$this->
id.$get_params;
3828 if ($option !=
'nolink') {
3830 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3831 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3832 $add_save_lastsearch_values = 1;
3834 if ($add_save_lastsearch_values) {
3835 $url .=
'&save_lastsearch_values=1';
3841 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
3842 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
3843 $label = $langs->trans(
"Proposal");
3844 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3846 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3847 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
3850 $linkstart =
'<a href="'.$url.
'"';
3851 $linkstart .= $linkclose.
'>';
3854 $result .= $linkstart;
3856 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
3858 if ($withpicto != 2) {
3859 $result .= $this->ref;
3861 $result .= $linkend;
3863 if ($addlinktonotes >= 0) {
3866 if ($addlinktonotes == 0) {
3867 if (!empty($this->note_private) || !empty($this->note_public)) {
3868 $txttoshow = $langs->trans(
'ViewPrivateNote');
3870 } elseif ($addlinktonotes == 1) {
3871 if (!empty($this->note_private)) {
3874 } elseif ($addlinktonotes == 2) {
3875 if (!empty($this->note_public)) {
3878 } elseif ($addlinktonotes == 3) {
3879 if ($user->socid > 0) {
3880 if (!empty($this->note_public)) {
3884 if (!empty($this->note_public)) {
3887 if (!empty($this->note_private)) {
3888 if (!empty($txttoshow)) {
3889 $txttoshow .=
'<br><br>';
3897 $result .=
' <span class="note inline-block">';
3898 $result .=
'<a href="'.DOL_URL_ROOT.
'/comm/propal/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($txttoshow).
'">';
3901 $result .=
'</span>';
3906 $hookmanager->initHooks(array($this->element .
'dao'));
3907 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
3908 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3910 $result = $hookmanager->resPrint;
3912 $result .= $hookmanager->resPrint;
3939 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3941 global $conf, $langs;
3943 $langs->load(
"propale");
3944 $outputlangs->load(
"products");
3949 if ($this->model_pdf) {
3950 $modele = $this->model_pdf;
3951 } elseif (!empty($conf->global->PROPALE_ADDON_PDF)) {
3952 $modele = $conf->global->PROPALE_ADDON_PDF;
3956 $modelpath =
"core/modules/propale/doc/";
3958 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4006 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
4008 $return =
'<div class="box-flex-item box-flex-grow-zero">';
4009 $return .=
'<div class="info-box info-box-sm">';
4010 $return .=
'<span class="info-box-icon bg-infobox-action">';
4012 $return .=
'</span>';
4013 $return .=
'<div class="info-box-content">';
4014 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
4015 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
4016 if (property_exists($this,
'fk_project')) {
4017 $return .=
'<span class="info-box-ref"> | '.$this->fk_project.
'</span>';
4019 if (property_exists($this,
'author')) {
4020 $return .=
'<br><span class="info-box-label">'.$this->author.
'</span>';
4022 if (property_exists($this,
'total_ht')) {
4023 $return .=
'<br><span class="" >'.$langs->trans(
"AmountHT").
' : </span><span class="info-box-label amount">'.
price($this->total_ht).
'</span>';
4025 if (method_exists($this,
'getLibStatut')) {
4026 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
4028 $return .=
'</div>';
4029 $return .=
'</div>';
4030 $return .=
'</div>';
4043 public $element =
'propaldet';
4048 public $table_element =
'propaldet';
4054 public $fk_parent_line;
4072 public $vat_src_code;
4075 public $remise_percent;
4076 public $fk_remise_except;
4080 public $fk_fournprice;
4085 public $special_code;
4090 public $info_bits = 0;
4119 public $product_ref;
4134 public $product_label;
4139 public $product_desc;
4145 public $product_tobatch;
4151 public $product_barcode;
4153 public $localtax1_tx;
4154 public $localtax2_tx;
4155 public $localtax1_type;
4156 public $localtax2_type;
4157 public $total_localtax1;
4158 public $total_localtax2;
4163 public $skip_update_total;
4166 public $fk_multicurrency;
4167 public $multicurrency_code;
4168 public $multicurrency_subprice;
4169 public $multicurrency_total_ht;
4170 public $multicurrency_total_tva;
4171 public $multicurrency_total_ttc;
4192 $sql =
'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.vat_src_code, pd.tva_tx,';
4193 $sql .=
' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
4194 $sql .=
' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
4195 $sql .=
' pd.fk_unit,';
4196 $sql .=
' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
4197 $sql .=
' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
4198 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
4199 $sql .=
' pd.date_start, pd.date_end, pd.product_type';
4200 $sql .=
' FROM '.MAIN_DB_PREFIX.
'propaldet as pd';
4201 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON pd.fk_product = p.rowid';
4202 $sql .=
' WHERE pd.rowid = '.((int) $rowid);
4204 $result = $this->db->query(
$sql);
4206 $objp = $this->db->fetch_object($result);
4209 $this->
id = $objp->rowid;
4210 $this->
rowid = $objp->rowid;
4211 $this->fk_propal = $objp->fk_propal;
4212 $this->fk_parent_line = $objp->fk_parent_line;
4213 $this->label = $objp->custom_label;
4214 $this->desc = $objp->description;
4215 $this->qty = $objp->qty;
4216 $this->
price = $objp->price;
4217 $this->subprice = $objp->subprice;
4218 $this->vat_src_code = $objp->vat_src_code;
4219 $this->tva_tx = $objp->tva_tx;
4220 $this->remise = $objp->remise;
4221 $this->remise_percent = $objp->remise_percent;
4222 $this->fk_remise_except = $objp->fk_remise_except;
4223 $this->fk_product = $objp->fk_product;
4224 $this->info_bits = $objp->info_bits;
4226 $this->total_ht = $objp->total_ht;
4227 $this->total_tva = $objp->total_tva;
4228 $this->total_ttc = $objp->total_ttc;
4230 $this->fk_fournprice = $objp->fk_fournprice;
4232 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
4233 $this->pa_ht = $marginInfos[0];
4234 $this->marge_tx = $marginInfos[1];
4235 $this->marque_tx = $marginInfos[2];
4237 $this->special_code = $objp->special_code;
4238 $this->product_type = $objp->product_type;
4239 $this->rang = $objp->rang;
4241 $this->
ref = $objp->product_ref;
4242 $this->product_ref = $objp->product_ref;
4243 $this->libelle = $objp->product_label;
4244 $this->product_label = $objp->product_label;
4245 $this->product_desc = $objp->product_desc;
4246 $this->fk_unit = $objp->fk_unit;
4248 $this->date_start = $this->db->jdate($objp->date_start);
4249 $this->date_end = $this->db->jdate($objp->date_end);
4252 $this->fk_multicurrency = $objp->fk_multicurrency;
4253 $this->multicurrency_code = $objp->multicurrency_code;
4254 $this->multicurrency_subprice = $objp->multicurrency_subprice;
4255 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
4256 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
4257 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
4261 $this->db->free($result);
4280 global $conf, $user;
4284 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
4286 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht ==
'');
4289 if (empty($this->tva_tx)) {
4292 if (empty($this->localtax1_tx)) {
4293 $this->localtax1_tx = 0;
4295 if (empty($this->localtax2_tx)) {
4296 $this->localtax2_tx = 0;
4298 if (empty($this->localtax1_type)) {
4299 $this->localtax1_type = 0;
4301 if (empty($this->localtax2_type)) {
4302 $this->localtax2_type = 0;
4304 if (empty($this->total_localtax1)) {
4305 $this->total_localtax1 = 0;
4307 if (empty($this->total_localtax2)) {
4308 $this->total_localtax2 = 0;
4310 if (empty($this->rang)) {
4313 if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
4314 $this->remise_percent = 0;
4316 if (empty($this->info_bits)) {
4317 $this->info_bits = 0;
4319 if (empty($this->special_code)) {
4320 $this->special_code = 0;
4322 if (empty($this->fk_parent_line)) {
4323 $this->fk_parent_line = 0;
4325 if (empty($this->fk_fournprice)) {
4326 $this->fk_fournprice = 0;
4328 if (!is_numeric($this->qty)) {
4331 if (empty($this->pa_ht)) {
4334 if (empty($this->multicurrency_subprice)) {
4335 $this->multicurrency_subprice = 0;
4337 if (empty($this->multicurrency_total_ht)) {
4338 $this->multicurrency_total_ht = 0;
4340 if (empty($this->multicurrency_total_tva)) {
4341 $this->multicurrency_total_tva = 0;
4343 if (empty($this->multicurrency_total_ttc)) {
4344 $this->multicurrency_total_ttc = 0;
4348 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
4349 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
4352 $this->pa_ht = $result;
4357 if ($this->product_type < 0) {
4364 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'propaldet';
4365 $sql .=
' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
4366 $sql .=
' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
4367 $sql .=
' subprice, remise_percent, ';
4368 $sql .=
' info_bits, ';
4369 $sql .=
' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
4370 $sql .=
' fk_unit,';
4371 $sql .=
' date_start, date_end';
4372 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
4373 $sql .=
" VALUES (".$this->fk_propal.
",";
4374 $sql .=
" ".($this->fk_parent_line > 0 ?
"'".$this->db->escape($this->fk_parent_line).
"'" :
"null").
",";
4375 $sql .=
" ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
4376 $sql .=
" '".$this->db->escape($this->desc).
"',";
4377 $sql .=
" ".($this->fk_product ?
"'".$this->db->escape($this->fk_product).
"'" :
"null").
",";
4378 $sql .=
" '".$this->db->escape($this->product_type).
"',";
4379 $sql .=
" ".($this->fk_remise_except ?
"'".$this->db->escape($this->fk_remise_except).
"'" :
"null").
",";
4380 $sql .=
" ".price2num($this->qty,
'MS').
",";
4381 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4382 $sql .=
" ".price2num($this->tva_tx).
",";
4383 $sql .=
" ".price2num($this->localtax1_tx).
",";
4384 $sql .=
" ".price2num($this->localtax2_tx).
",";
4385 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4386 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4387 $sql .=
" ".(price2num($this->subprice) !==
'' ?
price2num($this->subprice,
'MU') :
"null").
",";
4388 $sql .=
" ".price2num($this->remise_percent, 3).
",";
4389 $sql .=
" ".(isset($this->info_bits) ? ((int) $this->info_bits) :
"null").
",";
4390 $sql .=
" ".price2num($this->total_ht,
'MT').
",";
4391 $sql .=
" ".price2num($this->total_tva,
'MT').
",";
4392 $sql .=
" ".price2num($this->total_localtax1,
'MT').
",";
4393 $sql .=
" ".price2num($this->total_localtax2,
'MT').
",";
4394 $sql .=
" ".price2num($this->total_ttc,
'MT').
",";
4395 $sql .=
" ".(!empty($this->fk_fournprice) ?
"'".$this->db->escape($this->fk_fournprice).
"'" :
"null").
",";
4396 $sql .=
" ".(isset($this->pa_ht) ?
"'".price2num($this->pa_ht).
"'" :
"null").
",";
4397 $sql .=
' '.((int) $this->special_code).
',';
4398 $sql .=
' '.((int) $this->rang).
',';
4399 $sql .=
' '.(empty($this->fk_unit) ?
'NULL' : ((int) $this->fk_unit)).
',';
4400 $sql .=
" ".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
',';
4401 $sql .=
" ".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4402 $sql .=
", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) :
'null');
4403 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4404 $sql .=
", ".price2num($this->multicurrency_subprice,
'CU');
4405 $sql .=
", ".price2num($this->multicurrency_total_ht,
'CT');
4406 $sql .=
", ".price2num($this->multicurrency_total_tva,
'CT');
4407 $sql .=
", ".price2num($this->multicurrency_total_ttc,
'CT');
4410 dol_syslog(get_class($this).
'::insert', LOG_DEBUG);
4411 $resql = $this->db->query(
$sql);
4413 $this->
rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
'propaldet');
4416 $this->
id = $this->rowid;
4423 if (!$error && !$notrigger) {
4425 $result = $this->
call_trigger(
'LINEPROPAL_INSERT', $user);
4427 $this->db->rollback();
4433 $this->db->commit();
4436 $this->error = $this->db->error().
" sql=".
$sql;
4437 $this->db->rollback();
4449 public function delete(
User $user, $notrigger = 0)
4458 $result = $this->
call_trigger(
'LINEPROPAL_DELETE', $user);
4466 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"propaldet WHERE rowid = " . ((int) $this->
rowid);
4467 dol_syslog(
"PropaleLigne::delete", LOG_DEBUG);
4468 if ($this->db->query(
$sql)) {
4471 $this->
id = $this->rowid;
4475 dol_syslog(get_class($this) .
"::delete error -4 " . $this->error, LOG_ERR);
4479 $this->error = $this->db->error() .
" sql=" .
$sql;
4485 $this->db->rollback();
4488 $this->db->commit();
4501 global $conf, $user;
4505 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht ==
'');
4507 if (empty($this->
id) && !empty($this->
rowid)) {
4508 $this->
id = $this->rowid;
4512 if (empty($this->tva_tx)) {
4515 if (empty($this->localtax1_tx)) {
4516 $this->localtax1_tx = 0;
4518 if (empty($this->localtax2_tx)) {
4519 $this->localtax2_tx = 0;
4521 if (empty($this->total_localtax1)) {
4522 $this->total_localtax1 = 0;
4524 if (empty($this->total_localtax2)) {
4525 $this->total_localtax2 = 0;
4527 if (empty($this->localtax1_type)) {
4528 $this->localtax1_type = 0;
4530 if (empty($this->localtax2_type)) {
4531 $this->localtax2_type = 0;
4533 if (empty($this->marque_tx)) {
4534 $this->marque_tx = 0;
4536 if (empty($this->marge_tx)) {
4537 $this->marge_tx = 0;
4539 if (empty($this->
price)) {
4542 if (empty($this->remise_percent)) {
4543 $this->remise_percent = 0;
4545 if (empty($this->info_bits)) {
4546 $this->info_bits = 0;
4548 if (empty($this->special_code)) {
4549 $this->special_code = 0;
4551 if (empty($this->fk_parent_line)) {
4552 $this->fk_parent_line = 0;
4554 if (empty($this->fk_fournprice)) {
4555 $this->fk_fournprice = 0;
4557 if (empty($this->subprice)) {
4558 $this->subprice = 0;
4560 if (empty($this->pa_ht)) {
4565 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
4566 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
4569 $this->pa_ht = $result;
4576 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propaldet SET";
4577 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4578 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
4579 $sql .=
", product_type=".$this->product_type;
4580 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4581 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4582 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
4583 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
4584 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4585 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4586 $sql .=
", qty='".price2num($this->qty).
"'";
4587 $sql .=
", subprice=".price2num($this->subprice);
4588 $sql .=
", remise_percent=".price2num($this->remise_percent);
4591 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4592 if (empty($this->skip_update_total)) {
4593 $sql .=
", total_ht=".price2num($this->total_ht);
4594 $sql .=
", total_tva=".price2num($this->total_tva);
4595 $sql .=
", total_ttc=".price2num($this->total_ttc);
4596 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
4597 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
4599 $sql .=
", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ?
"'".$this->db->escape($this->fk_fournprice).
"'" :
"null");
4600 $sql .=
", buy_price_ht=".price2num($this->pa_ht);
4601 if (strlen($this->special_code)) {
4602 $sql .=
", special_code=".$this->special_code;
4604 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line :
"null");
4605 if (!empty($this->rang)) {
4606 $sql .=
", rang=".((int) $this->rang);
4608 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4609 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4610 $sql .=
", fk_unit=".(!$this->fk_unit ?
'NULL' : $this->fk_unit);
4613 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4614 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4615 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4616 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4618 $sql .=
" WHERE rowid = ".((int) $this->
id);
4620 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
4621 $resql = $this->db->query(
$sql);
4630 if (!$error && !$notrigger) {
4632 $result = $this->
call_trigger(
'LINEPROPAL_MODIFY', $user);
4634 $this->db->rollback();
4640 $this->db->commit();
4643 $this->error = $this->db->error();
4644 $this->db->rollback();
4662 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propaldet SET";
4663 $sql .=
" total_ht=".price2num($this->total_ht,
'MT');
4664 $sql .=
",total_tva=".price2num($this->total_tva,
'MT');
4665 $sql .=
",total_ttc=".price2num($this->total_ttc,
'MT');
4666 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
4668 dol_syslog(
"PropaleLigne::update_total", LOG_DEBUG);
4670 $resql = $this->db->query(
$sql);
4672 $this->db->commit();
4675 $this->error = $this->db->error();
4676 $this->db->rollback();
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
defineBuyPrice($unitPrice=0.0, $discountPercent=0.0, $fk_product=0)
Get buy price to use for margin calculation.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
setErrorsFromObject($object)
setErrorsFromObject
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check an object id/ref exists If you don't need/want to instantiate object and just need to know if o...
updateRangOfLine($rowid, $rang)
Update position of line (rang)
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
fetch_project()
Load the project with id $this->fk_project into this->project.
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage absolute discounts.
Class to manage Dolibarr database access.
static getIdFromCode($dbs, $code)
Get id of currency from code.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
File of class to manage predefined price products or services by customer.
Class to manage proposals.
getTooltipContentArray($params)
getTooltipContentArray
const STATUS_DRAFT
Draft status.
fetch_lines($only_product=0, $loadalsotranslation=0, $filters='')
Load array lines.
set_date($user, $date, $notrigger=0)
Define proposal date.
const STATUS_SIGNED
Signed quote.
getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=-1)
Return clicable link of object (with eventually picto)
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
InvoiceArrayList($id)
Returns an array with id and ref of related invoices.
availability($availability_id, $notrigger=0)
Change the delivery time.
const STATUS_NOTSIGNED
Not signed quote.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set delivery date.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
set_remise_percent($user, $remise, $notrigger=0)
Set an overall discount on the proposal.
classifyBilled(User $user, $notrigger=0, $note='')
Classify the proposal to status Billed.
fetch($rowid, $ref='', $ref_ext='', $forceentity=0)
Load a proposal from database.
set_availability($user, $id, $notrigger=0)
Set delivery.
update(User $user, $notrigger=0)
Update database.
demand_reason($demand_reason_id, $notrigger=0)
Change source demand.
info($id)
Object Proposal Information.
const STATUS_BILLED
Billed or processed quote.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLibStatut($mode=0)
Return label of status of proposal (draft, validated, ...)
getLinesArray($filters='')
Retrieve an array of proposal lines.
insert_discount($idremise)
Adding line of fixed discount in the proposal in DB.
getNextNumRef($soc)
Returns the reference to the following non used Proposal used depending on the active numbering modul...
LibStatut($status, $mode=1)
Return label of a status (draft, validated, ...)
valid($user, $notrigger=0)
Set status to validated.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
set_ref_client($user, $ref_client, $notrigger=0)
Set customer reference number.
setDraft($user, $notrigger=0)
Set draft status.
set_echeance($user, $date_end_validity, $notrigger=0)
Define end validity date.
set_demand_reason($user, $id, $notrigger=0)
Set source of demand.
set_remise_absolue($user, $remise, $notrigger=0)
Set an absolute overall discount on the proposal.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
deleteline($lineid, $id=0)
Delete detail line.
create($user, $notrigger=0)
Create commercial proposal into database this->ref can be set or empty.
liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datep', $sortorder='DESC')
Return list of proposal (eventually filtered on user) into an array.
add_product($idproduct, $qty, $remise_percent=0)
Add line into array ->lines $this->thirdparty should be loaded.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='', $date_start='', $date_end='', $array_options=0, $fk_unit=null, $origin='', $origin_id=0, $pu_ht_devise=0, $fk_remise_except=0, $noupdateafterinsertline=0)
Add a proposal line into database (linked to product/service or not) The parameters are already suppo...
initAsSpecimen()
Initialise an instance with random values.
closeProposal($user, $status, $note='', $notrigger=0)
Close/set the commercial proposal to status signed or refused (fill also date signature)
reopen($user, $status, $note='', $notrigger=0)
Reopen the commercial proposal.
__construct($db, $socid=0, $propalid=0)
Constructor.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=0, $pa_ht=0, $label='', $type=0, $date_start='', $date_end='', $array_options=0, $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $rang=0)
Update a proposal line.
getInvoiceArrayList()
Returns an array with the numbers of related invoices.
set_date_livraison($user, $delivery_date, $notrigger=0)
Set delivery date.
const STATUS_VALIDATED
Validated status.
createFromClone(User $user, $socid=0, $forceentity=null, $update_prices=false, $update_desc=false)
Load an object from its id and create a new one in database.
Class to manage commercial proposal lines.
__construct($db)
Class line Contructor.
update($notrigger=0)
Update propal line object into DB.
fetch($rowid)
Retrieve the propal line object.
insert($notrigger=0)
Insert object line propal in database.
update_total()
Update DB line fields total_xxx Used by migration.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
trait CommonIncoterm
Superclass for incoterm classes.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
div float
Buy price without taxes.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.