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;
145 public $date_creation;
156 public $date_validation;
161 public $date_signature;
166 public $user_signature;
183 public $date_livraison;
188 public $delivery_date;
191 public $fin_validite;
193 public $user_author_id;
194 public $user_valid_id;
195 public $user_close_id;
213 public $cond_reglement_code;
214 public $deposit_percent;
215 public $mode_reglement_code;
216 public $remise_percent;
233 public $address_type;
236 public $availability_id;
237 public $availability_code;
239 public $duree_validite;
241 public $demand_reason_id;
242 public $demand_reason_code;
244 public $warehouse_id;
246 public $extraparams = array();
251 public $lines = array();
254 public $labelStatus = array();
255 public $labelStatusShort = array();
261 public $fk_multicurrency;
263 public $multicurrency_code;
264 public $multicurrency_tx;
265 public $multicurrency_total_ht;
266 public $multicurrency_total_tva;
267 public $multicurrency_total_ttc;
298 public $fields = array(
299 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
300 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>15,
'index'=>1),
301 'ref' =>array(
'type'=>
'varchar(30)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>20),
302 'ref_client' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefCustomer',
'enabled'=>1,
'visible'=>-1,
'position'=>22),
303 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefExt',
'enabled'=>1,
'visible'=>0,
'position'=>40),
304 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'position'=>23),
305 '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),
306 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
307 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
308 'datep' =>array(
'type'=>
'date',
'label'=>
'Date',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
309 'fin_validite' =>array(
'type'=>
'datetime',
'label'=>
'DateEnd',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
310 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
311 'date_cloture' =>array(
'type'=>
'datetime',
'label'=>
'DateClosing',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
312 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
313 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>85),
314 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
315 'fk_user_cloture' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user cloture',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
316 'price' =>array(
'type'=>
'double',
'label'=>
'Price',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
317 'remise_percent' =>array(
'type'=>
'double',
'label'=>
'RelativeDiscount',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
320 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>125,
'isameasure'=>1),
321 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'VAT',
'enabled'=>1,
'visible'=>-1,
'position'=>130,
'isameasure'=>1),
322 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'LocalTax1',
'enabled'=>1,
'visible'=>-1,
'position'=>135,
'isameasure'=>1),
323 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'LocalTax2',
'enabled'=>1,
'visible'=>-1,
'position'=>140,
'isameasure'=>1),
324 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>145,
'isameasure'=>1),
325 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'BankAccount',
'enabled'=>
'$conf->banque->enabled',
'visible'=>-1,
'position'=>150),
326 'fk_currency' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
327 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
328 'deposit_percent' =>array(
'type'=>
'varchar(63)',
'label'=>
'DepositPercent',
'enabled'=>1,
'visible'=>-1,
'position'=>161),
329 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
330 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>170),
331 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>175),
332 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'PDFTemplate',
'enabled'=>1,
'visible'=>0,
'position'=>180),
333 'date_livraison' =>array(
'type'=>
'date',
'label'=>
'DateDeliveryPlanned',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
334 'fk_shipping_method' =>array(
'type'=>
'integer',
'label'=>
'ShippingMethod',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
335 'fk_warehouse' =>array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Fk warehouse',
'enabled'=>
'$conf->stock->enabled',
'visible'=>-1,
'position'=>191),
336 'fk_availability' =>array(
'type'=>
'integer',
'label'=>
'Availability',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
337 'fk_delivery_address' =>array(
'type'=>
'integer',
'label'=>
'DeliveryAddress',
'enabled'=>1,
'visible'=>0,
'position'=>200),
338 'fk_input_reason' =>array(
'type'=>
'integer',
'label'=>
'InputReason',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
339 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
340 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>
'$conf->incoterm->enabled',
'visible'=>-1,
'position'=>220),
341 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLabel',
'enabled'=>
'$conf->incoterm->enabled',
'visible'=>-1,
'position'=>225),
342 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'MulticurrencyID',
'enabled'=>1,
'visible'=>-1,
'position'=>230),
343 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'MulticurrencyCurrency',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>235),
344 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyRate',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>240,
'isameasure'=>1),
345 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountHT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>245,
'isameasure'=>1),
346 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountVAT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>250,
'isameasure'=>1),
347 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountTTC',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>255,
'isameasure'=>1),
348 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>-1,
'position'=>260),
349 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>500),
350 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
385 global $conf, $langs;
389 $this->socid = $socid;
390 $this->
id = $propalid;
392 $this->duree_validite =
getDolGlobalInt(
'PROPALE_VALIDITY_DURATION', 0);
408 public function add_product($idproduct, $qty, $remise_percent = 0)
411 global $conf, $mysoc;
417 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
418 if ($idproduct > 0) {
420 $prod->fetch($idproduct);
422 $productdesc = $prod->description;
426 if (empty($tva_tx)) {
431 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
432 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
435 if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) {
436 $price = $prod->multiprices[$this->thirdparty->price_level];
443 $line->fk_product = $idproduct;
444 $line->desc = $productdesc;
447 $line->remise_percent = $remise_percent;
448 $line->vat_src_code = $vat_src_code;
449 $line->tva_tx = $tva_tx;
450 $line->fk_unit = $prod->fk_unit;
452 $line->info_bits = 1;
455 $this->lines[] = $line;
473 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
474 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
479 $result =
$remise->fetch($idremise);
483 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
484 $this->
db->rollback();
490 $this->line->context = $this->context;
492 $line->fk_propal = $this->id;
493 $line->fk_remise_except =
$remise->id;
494 $line->desc =
$remise->description;
495 $line->vat_src_code =
$remise->vat_src_code;
496 $line->tva_tx =
$remise->tva_tx;
497 $line->subprice = -
$remise->amount_ht;
498 $line->fk_product = 0;
500 $line->remise_percent = 0;
502 $line->info_bits = 2;
505 $line->price = -
$remise->amount_ht;
507 $line->total_ht = -
$remise->amount_ht;
508 $line->total_tva = -
$remise->amount_tva;
509 $line->total_ttc = -
$remise->amount_ttc;
511 $result = $line->insert();
518 $this->
db->rollback();
522 $this->error = $line->error;
523 $this->errors = $line->errors;
524 $this->
db->rollback();
528 $this->
db->rollback();
570 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)
572 global $mysoc, $conf, $langs;
574 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);
576 if ($this->statut == self::STATUS_DRAFT) {
577 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
580 if (empty($remise_percent)) {
586 if (empty($info_bits)) {
592 if (empty($fk_parent_line) || $fk_parent_line < 0) {
596 $remise_percent =
price2num($remise_percent);
599 $pu_ht_devise =
price2num($pu_ht_devise);
601 if (!preg_match(
'/\((.*)\)/', $txtva)) {
607 if ($price_base_type ==
'HT') {
618 if ($date_start && $date_end && $date_start > $date_end) {
619 $langs->load(
"errors");
620 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
626 $product_type = $type;
627 if (!empty($fk_product) && $fk_product > 0) {
629 $result = $product->fetch($fk_product);
630 $product_type = $product->type;
632 if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL) && $product_type == 0 && $product->stock_reel < $qty) {
633 $langs->load(
"errors");
634 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref);
635 $this->
db->rollback();
651 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
652 $vat_src_code = $reg[1];
653 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
656 $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);
658 $total_ht = $tabprice[0];
659 $total_tva = $tabprice[1];
660 $total_ttc = $tabprice[2];
661 $total_localtax1 = $tabprice[9];
662 $total_localtax2 = $tabprice[10];
663 $pu_ht = $tabprice[3];
664 $pu_tva = $tabprice[4];
665 $pu_ttc = $tabprice[5];
668 $multicurrency_total_ht = $tabprice[16];
669 $multicurrency_total_tva = $tabprice[17];
670 $multicurrency_total_ttc = $tabprice[18];
671 $pu_ht_devise = $tabprice[19];
675 if ($ranktouse == -1) {
676 $rangmax = $this->
line_max($fk_parent_line);
677 $ranktouse = $rangmax + 1;
684 if ($remise_percent > 0) {
685 $remise = round(($pu * $remise_percent / 100), 2);
692 $this->line->context = $this->context;
694 $this->line->fk_propal = $this->id;
695 $this->line->label = $label;
696 $this->line->desc = $desc;
697 $this->line->qty = $qty;
699 $this->line->vat_src_code = $vat_src_code;
700 $this->line->tva_tx = $txtva;
701 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
702 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
703 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
704 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
705 $this->line->fk_product = $fk_product;
706 $this->line->product_type = $type;
707 $this->line->fk_remise_except = $fk_remise_except;
708 $this->line->remise_percent = $remise_percent;
709 $this->line->subprice = $pu_ht;
710 $this->line->rang = $ranktouse;
711 $this->line->info_bits = $info_bits;
712 $this->line->total_ht = $total_ht;
713 $this->line->total_tva = $total_tva;
714 $this->line->total_localtax1 = $total_localtax1;
715 $this->line->total_localtax2 = $total_localtax2;
716 $this->line->total_ttc = $total_ttc;
717 $this->line->special_code = $special_code;
718 $this->line->fk_parent_line = $fk_parent_line;
719 $this->line->fk_unit = $fk_unit;
721 $this->line->date_start = $date_start;
722 $this->line->date_end = $date_end;
724 $this->line->fk_fournprice = $fk_fournprice;
725 $this->line->pa_ht = $pa_ht;
727 $this->line->origin_id = $origin_id;
728 $this->line->origin = $origin;
731 $this->line->fk_multicurrency = $this->fk_multicurrency;
732 $this->line->multicurrency_code = $this->multicurrency_code;
733 $this->line->multicurrency_subprice = $pu_ht_devise;
734 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
735 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
736 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
739 if (empty($qty) && empty($special_code)) {
740 $this->line->special_code = 3;
744 $this->line->price =
$price;
746 if (is_array($array_options) && count($array_options) > 0) {
747 $this->line->array_options = $array_options;
750 $result = $this->line->insert();
753 if (!empty($fk_parent_line)) {
755 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
756 $linecount = count($this->lines);
757 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
763 if (empty($noupdateafterinsertline)) {
769 return $this->line->id;
771 $this->error = $this->
db->error();
772 $this->
db->rollback();
776 $this->error = $this->line->error;
777 $this->errors = $this->line->errors;
778 $this->
db->rollback();
782 dol_syslog(get_class($this).
"::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR);
817 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)
819 global $mysoc, $langs;
821 dol_syslog(get_class($this).
"::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent,
822 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");
823 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
826 $remise_percent =
price2num($remise_percent);
829 $pu_ht_devise =
price2num($pu_ht_devise);
830 if (!preg_match(
'/\((.*)\)/', $txtva)) {
836 if (empty($qty) && empty($special_code)) {
839 if (!empty($qty) && $special_code == 3) {
846 if ($date_start && $date_end && $date_start > $date_end) {
847 $langs->load(
"errors");
848 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
852 if ($this->statut == self::STATUS_DRAFT) {
865 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
866 $vat_src_code = $reg[1];
867 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
870 $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);
871 $total_ht = $tabprice[0];
872 $total_tva = $tabprice[1];
873 $total_ttc = $tabprice[2];
874 $total_localtax1 = $tabprice[9];
875 $total_localtax2 = $tabprice[10];
876 $pu_ht = $tabprice[3];
877 $pu_tva = $tabprice[4];
878 $pu_ttc = $tabprice[5];
881 $multicurrency_total_ht = $tabprice[16];
882 $multicurrency_total_tva = $tabprice[17];
883 $multicurrency_total_ttc = $tabprice[18];
884 $pu_ht_devise = $tabprice[19];
889 if ($remise_percent > 0) {
890 $remise = round(($pu * $remise_percent / 100), 2);
896 $line->fetch($rowid);
898 $staticline = clone $line;
900 $line->oldline = $staticline;
902 $this->line->context = $this->context;
903 $this->line->rang = $rang;
906 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
907 $rangmax = $this->
line_max($fk_parent_line);
908 $this->line->rang = $rangmax + 1;
911 $this->line->id = $rowid;
912 $this->line->label = $label;
913 $this->line->desc = $desc;
914 $this->line->qty = $qty;
915 $this->line->product_type = $type;
916 $this->line->vat_src_code = $vat_src_code;
917 $this->line->tva_tx = $txtva;
918 $this->line->localtax1_tx = $txlocaltax1;
919 $this->line->localtax2_tx = $txlocaltax2;
920 $this->line->localtax1_type = $localtaxes_type[0];
921 $this->line->localtax2_type = $localtaxes_type[2];
922 $this->line->remise_percent = $remise_percent;
923 $this->line->subprice = $pu_ht;
924 $this->line->info_bits = $info_bits;
926 $this->line->total_ht = $total_ht;
927 $this->line->total_tva = $total_tva;
928 $this->line->total_localtax1 = $total_localtax1;
929 $this->line->total_localtax2 = $total_localtax2;
930 $this->line->total_ttc = $total_ttc;
931 $this->line->special_code = $special_code;
932 $this->line->fk_parent_line = $fk_parent_line;
933 $this->line->skip_update_total = $skip_update_total;
934 $this->line->fk_unit = $fk_unit;
936 $this->line->fk_fournprice = $fk_fournprice;
937 $this->line->pa_ht = $pa_ht;
939 $this->line->date_start = $date_start;
940 $this->line->date_end = $date_end;
942 if (is_array($array_options) && count($array_options) > 0) {
944 foreach ($array_options as $key => $value) {
945 $this->line->array_options[$key] = $array_options[$key];
950 $this->line->multicurrency_subprice = $pu_ht_devise;
951 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
952 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
953 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
955 $result = $this->line->update($notrigger);
958 if (!empty($fk_parent_line)) {
964 $this->fk_propal = $this->id;
965 $this->
rowid = $rowid;
970 $this->error = $this->line->error;
971 $this->errors = $this->line->errors;
972 $this->
db->rollback();
976 dol_syslog(get_class($this).
"::updateline Erreur -2 Propal en mode incompatible pour cette action");
993 if ($this->statut == self::STATUS_DRAFT) {
998 $line->context = $this->context;
1001 $line->fetch($lineid);
1003 if ($id > 0 && $line->fk_propal != $id) {
1004 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1009 $staticline = clone $line;
1010 $line->oldline = $staticline;
1012 if ($line->delete($user) > 0) {
1015 $this->
db->commit();
1018 $this->error = $line->error;
1019 $this->errors = $line->errors;
1020 $this->
db->rollback();
1024 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1038 public function create($user, $notrigger = 0)
1040 global $conf, $hookmanager, $mysoc;
1046 if (empty($this->date)) {
1049 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1050 if (empty($this->availability_id)) {
1051 $this->availability_id = 0;
1053 if (empty($this->demand_reason_id)) {
1054 $this->demand_reason_id = 0;
1058 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1063 if (empty($this->fk_multicurrency)) {
1064 $this->multicurrency_code = $conf->currency;
1065 $this->fk_multicurrency = 0;
1066 $this->multicurrency_tx = 1;
1070 $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
1077 $this->error =
"Failed to fetch company";
1078 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1083 if (!empty($this->
ref)) {
1086 $this->error =
'ErrorRefAlreadyExists';
1087 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1088 $this->
db->rollback();
1093 if (empty($this->date)) {
1094 $this->error =
"Date of proposal is required";
1095 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1103 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"propal (";
1107 $sql .=
", remise_percent";
1108 $sql .=
", remise_absolue";
1109 $sql .=
", total_tva";
1110 $sql .=
", total_ttc";
1114 $sql .=
", fk_user_author";
1115 $sql .=
", note_private";
1116 $sql .=
", note_public";
1117 $sql .=
", model_pdf";
1118 $sql .=
", fin_validite";
1119 $sql .=
", fk_cond_reglement";
1120 $sql .=
", deposit_percent";
1121 $sql .=
", fk_mode_reglement";
1122 $sql .=
", fk_account";
1123 $sql .=
", ref_client";
1124 $sql .=
", ref_ext";
1125 $sql .=
", date_livraison";
1126 $sql .=
", fk_shipping_method";
1127 $sql .=
", fk_warehouse";
1128 $sql .=
", fk_availability";
1129 $sql .=
", fk_input_reason";
1130 $sql .=
", fk_projet";
1131 $sql .=
", fk_incoterms";
1132 $sql .=
", location_incoterms";
1134 $sql .=
", fk_multicurrency";
1135 $sql .=
", multicurrency_code";
1136 $sql .=
", multicurrency_tx";
1138 $sql .=
" VALUES (";
1139 $sql .= $this->socid;
1141 $sql .=
", ".((float) $this->remise);
1142 $sql .=
", ".($this->remise_percent ? ((
float) $this->remise_percent) :
'NULL');
1143 $sql .=
", ".($this->remise_absolue ? ((
float) $this->remise_absolue) :
'NULL');
1146 $sql .=
", '".$this->db->idate($this->date).
"'";
1147 $sql .=
", '".$this->db->idate($now).
"'";
1148 $sql .=
", '(PROV)'";
1149 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
1150 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1151 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1152 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1153 $sql .=
", ".($this->fin_validite !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
"NULL");
1154 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1155 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
'NULL');
1156 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1157 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1158 $sql .=
", '".$this->db->escape($this->ref_client).
"'";
1159 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
1160 $sql .=
", ".(empty($delivery_date) ?
"NULL" :
"'".$this->db->idate($delivery_date).
"'");
1161 $sql .=
", ".($this->shipping_method_id > 0 ? $this->shipping_method_id :
'NULL');
1162 $sql .=
", ".($this->warehouse_id > 0 ? $this->warehouse_id :
'NULL');
1163 $sql .=
", ".$this->availability_id;
1164 $sql .=
", ".$this->demand_reason_id;
1165 $sql .=
", ".($this->fk_project ? $this->fk_project :
"null");
1166 $sql .=
", ".(int) $this->fk_incoterms;
1167 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1168 $sql .=
", ".setEntity($this);
1169 $sql .=
", ".(int) $this->fk_multicurrency;
1170 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1171 $sql .=
", ".(double) $this->multicurrency_tx;
1174 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1175 $resql = $this->
db->query(
$sql);
1177 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"propal");
1180 $this->
ref =
'(PROV'.$this->id.
')';
1181 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"propal SET ref='".$this->
db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1183 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1184 $resql = $this->
db->query(
$sql);
1189 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1190 $this->linked_objects = $this->linkedObjectsIds;
1194 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1195 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1196 if (is_array($tmp_origin_id)) {
1197 foreach ($tmp_origin_id as $origin_id) {
1200 $this->error = $this->
db->lasterror();
1206 $origin_id = $tmp_origin_id;
1209 $this->error = $this->
db->lasterror();
1221 $fk_parent_line = 0;
1222 $num = count($this->lines);
1224 for ($i = 0; $i < $num; $i++) {
1225 if (!is_object($this->lines[$i])) {
1227 $line = (object) $this->lines[$i];
1229 $line = $this->lines[$i];
1232 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1233 $fk_parent_line = 0;
1236 $vatrate = $line->tva_tx;
1237 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', $vatrate)) {
1238 $vatrate .=
' ('.$line->vat_src_code.
')';
1241 if (!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) {
1242 $originid = $line->origin_id;
1243 $origintype = $line->origin;
1245 $originid = $line->id;
1246 $origintype = $this->element;
1254 $line->localtax1_tx,
1255 $line->localtax2_tx,
1257 $line->remise_percent,
1261 $line->product_type,
1263 $line->special_code,
1265 $line->fk_fournprice,
1270 $line->array_options,
1281 $this->error = $this->
db->error;
1286 if ($result > 0 && $line->product_type == 9) {
1287 $fk_parent_line = $result;
1317 if (!$error && !$notrigger) {
1326 $this->error = $this->
db->lasterror();
1331 $this->error = $this->
db->lasterror();
1336 $this->
db->commit();
1337 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1340 $this->
db->rollback();
1344 $this->error = $this->
db->lasterror();
1345 $this->
db->rollback();
1361 global $conf, $hookmanager, $mysoc;
1370 $object =
new self($this->db);
1375 $object->fetch($this->
id);
1380 if (!empty($socid) && $socid != $object->socid) {
1381 if ($objsoc->fetch($socid) > 0) {
1382 $object->socid = $objsoc->id;
1383 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1384 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
null);
1385 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1386 $object->fk_delivery_address =
'';
1398 $object->fk_project =
'';
1402 $object->ref_client =
'';
1406 $objsoc->fetch($object->socid);
1410 if ($update_prices ===
true) {
1411 if ($objsoc->id > 0 && !empty($object->lines)) {
1412 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1414 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1417 foreach ($object->lines as $line) {
1418 if ($line->fk_product > 0) {
1420 $res = $prod->fetch($line->fk_product);
1422 $pu_ht = $prod->price;
1424 $remise_percent = $objsoc->remise_percent;
1426 if (!empty($conf->global->PRODUIT_MULTIPRICES) && $objsoc->price_level > 0) {
1427 $pu_ht = $prod->multiprices[$objsoc->price_level];
1428 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1429 if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) {
1430 $tva_tx = $prod->multiprices_tva_tx[$objsoc->price_level];
1433 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1435 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $objsoc->id);
1436 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1439 if (count($prodcustprice->lines) > 0) {
1440 $pu_ht =
price($prodcustprice->lines[0]->price);
1441 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1442 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1443 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1449 $line->subprice = $pu_ht;
1450 $line->tva_tx = $tva_tx;
1451 $line->remise_percent = $remise_percent;
1460 $object->entity = (!empty($forceentity) ? $forceentity : $object->entity);
1464 $object->user_author = $user->id;
1465 $object->user_valid = 0;
1466 $object->date = $now;
1467 $object->datep = $now;
1468 $object->fin_validite = $object->date + ($object->duree_validite * 24 * 3600);
1469 if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) {
1470 $object->ref_client =
'';
1473 $object->note_private =
'';
1474 $object->note_public =
'';
1477 $object->context[
'createfromclone'] =
'createfromclone';
1478 $result = $object->create($user);
1480 $this->error = $object->error;
1481 $this->errors = array_merge($this->errors, $object->errors);
1487 if ($object->copy_linked_contact($this,
'internal') < 0) {
1494 if ($this->socid == $object->socid) {
1495 if ($object->copy_linked_contact($this,
'external') < 0) {
1503 if (is_object($hookmanager)) {
1504 $parameters = array(
'objFrom'=>$this,
'clonedObj'=>$object);
1506 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1514 unset($object->context[
'createfromclone']);
1518 $this->
db->commit();
1521 $this->
db->rollback();
1535 public function fetch($rowid, $ref =
'', $ref_ext =
'', $forceentity = 0)
1537 $sql =
"SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
1538 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1539 $sql .=
", p.datec";
1540 $sql .=
", p.date_signature as dates";
1541 $sql .=
", p.date_valid as datev";
1542 $sql .=
", p.datep as dp";
1543 $sql .=
", p.fin_validite as dfv";
1544 $sql .=
", p.date_livraison as delivery_date";
1545 $sql .=
", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
1546 $sql .=
", p.note_private, p.note_public";
1547 $sql .=
", p.fk_projet as fk_project, p.fk_statut";
1548 $sql .=
", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1549 $sql .=
", p.fk_delivery_address";
1550 $sql .=
", p.fk_availability";
1551 $sql .=
", p.fk_input_reason";
1552 $sql .=
", p.fk_cond_reglement";
1553 $sql .=
", p.fk_mode_reglement";
1554 $sql .=
', p.fk_account';
1555 $sql .=
", p.fk_shipping_method";
1556 $sql .=
", p.fk_warehouse";
1557 $sql .=
", p.fk_incoterms, p.location_incoterms";
1558 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1559 $sql .=
", p.tms as date_modification";
1560 $sql .=
", i.libelle as label_incoterms";
1561 $sql .=
", c.label as statut_label";
1562 $sql .=
", ca.code as availability_code, ca.label as availability";
1563 $sql .=
", dr.code as demand_reason_code, dr.label as demand_reason";
1564 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1565 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1566 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
1567 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_propalst as c ON p.fk_statut = c.id';
1568 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.
getEntity(
'c_paiement').
')';
1569 $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').
')';
1570 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON p.fk_availability = ca.rowid';
1571 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
1572 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON p.fk_incoterms = i.rowid';
1575 if (!empty($forceentity)) {
1576 $sql .=
" WHERE p.entity = ".(int) $forceentity;
1578 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
1580 $sql .=
" AND p.ref='".$this->db->escape($ref).
"'";
1583 $sql .=
" WHERE p.rowid = ".((int) $rowid);
1586 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1587 $resql = $this->
db->query(
$sql);
1589 if ($this->
db->num_rows($resql)) {
1590 $obj = $this->
db->fetch_object($resql);
1592 $this->
id = $obj->rowid;
1593 $this->entity = $obj->entity;
1595 $this->
ref = $obj->ref;
1596 $this->ref_client = $obj->ref_client;
1597 $this->ref_ext = $obj->ref_ext;
1598 $this->remise = $obj->remise;
1599 $this->remise_percent = $obj->remise_percent;
1600 $this->remise_absolue = $obj->remise_absolue;
1601 $this->total = $obj->total_ttc;
1602 $this->total_ttc = $obj->total_ttc;
1603 $this->total_ht = $obj->total_ht;
1604 $this->total_tva = $obj->total_tva;
1605 $this->total_localtax1 = $obj->localtax1;
1606 $this->total_localtax2 = $obj->localtax2;
1608 $this->socid = $obj->fk_soc;
1609 $this->thirdparty =
null;
1611 $this->fk_project = $obj->fk_project;
1612 $this->project =
null;
1614 $this->model_pdf = $obj->model_pdf;
1615 $this->modelpdf = $obj->model_pdf;
1616 $this->last_main_doc = $obj->last_main_doc;
1617 $this->note = $obj->note_private;
1618 $this->note_private = $obj->note_private;
1619 $this->note_public = $obj->note_public;
1621 $this->status = (int) $obj->fk_statut;
1622 $this->statut = $this->status;
1623 $this->statut_libelle = $obj->statut_label;
1625 $this->datec = $this->db->jdate($obj->datec);
1626 $this->datev = $this->
db->jdate($obj->datev);
1627 $this->date_creation = $this->
db->jdate($obj->datec);
1628 $this->date_validation = $this->
db->jdate($obj->datev);
1629 $this->date_modification = $this->
db->jdate($obj->date_modification);
1630 $this->date_signature = $this->
db->jdate($obj->dates);
1631 $this->date = $this->
db->jdate($obj->dp);
1632 $this->datep = $this->
db->jdate($obj->dp);
1633 $this->fin_validite = $this->
db->jdate($obj->dfv);
1634 $this->date_livraison = $this->
db->jdate($obj->delivery_date);
1635 $this->delivery_date = $this->
db->jdate($obj->delivery_date);
1636 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1637 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
1638 $this->availability_id = $obj->fk_availability;
1639 $this->availability_code = $obj->availability_code;
1641 $this->demand_reason_id = $obj->fk_input_reason;
1642 $this->demand_reason_code = $obj->demand_reason_code;
1644 $this->fk_address = $obj->fk_delivery_address;
1646 $this->mode_reglement_id = $obj->fk_mode_reglement;
1647 $this->mode_reglement_code = $obj->mode_reglement_code;
1648 $this->mode_reglement = $obj->mode_reglement;
1649 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1650 $this->cond_reglement_id = $obj->fk_cond_reglement;
1651 $this->cond_reglement_code = $obj->cond_reglement_code;
1652 $this->cond_reglement = $obj->cond_reglement;
1653 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1654 $this->deposit_percent = $obj->deposit_percent;
1656 $this->extraparams = (array) json_decode($obj->extraparams,
true);
1658 $this->user_author_id = $obj->fk_user_author;
1659 $this->user_valid_id = $obj->fk_user_valid;
1660 $this->user_close_id = $obj->fk_user_cloture;
1663 $this->fk_incoterms = $obj->fk_incoterms;
1664 $this->location_incoterms = $obj->location_incoterms;
1665 $this->label_incoterms = $obj->label_incoterms;
1668 $this->fk_multicurrency = $obj->fk_multicurrency;
1669 $this->multicurrency_code = $obj->multicurrency_code;
1670 $this->multicurrency_tx = $obj->multicurrency_tx;
1671 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1672 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1673 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1675 if ($obj->fk_statut == self::STATUS_DRAFT) {
1676 $this->brouillon = 1;
1683 $this->
db->free($resql);
1685 $this->lines = array();
1696 $this->error =
"Record Not Found";
1699 $this->error = $this->
db->lasterror();
1718 if (isset($this->
ref)) {
1719 $this->
ref = trim($this->
ref);
1721 if (isset($this->ref_client)) {
1722 $this->ref_client = trim($this->ref_client);
1724 if (isset($this->note) || isset($this->note_private)) {
1725 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1727 if (isset($this->note_public)) {
1728 $this->note_public = trim($this->note_public);
1730 if (isset($this->model_pdf)) {
1731 $this->model_pdf = trim($this->model_pdf);
1733 if (isset($this->import_key)) {
1734 $this->import_key = trim($this->import_key);
1736 if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
1737 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1744 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET";
1745 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1746 $sql .=
" ref_client=".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
1747 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1748 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1749 $sql .=
" datep=".(strval($this->date) !=
'' ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1750 if (!empty($this->fin_validite)) {
1751 $sql .=
" fin_validite=".(strval($this->fin_validite) !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
'null').
",";
1753 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1754 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1755 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1756 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1757 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1758 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1759 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1760 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1761 $sql .=
" fk_user_valid=".(isset($this->user_valid) ? $this->user_valid :
"null").
",";
1762 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1763 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1764 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1765 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1766 $sql .=
" fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id :
"null").
",";
1767 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1768 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1769 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1770 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1771 $sql .=
" WHERE rowid=".((int) $this->
id);
1775 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1776 $resql = $this->
db->query(
$sql);
1779 $this->errors[] =
"Error ".$this->db->lasterror();
1789 if (!$error && !$notrigger) {
1800 foreach ($this->errors as $errmsg) {
1801 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1802 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1804 $this->
db->rollback();
1807 $this->
db->commit();
1823 public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $filters =
'')
1826 global $langs, $conf;
1828 $this->lines = array();
1830 $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,';
1831 $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,';
1832 $sql .=
' d.fk_unit,';
1833 $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,';
1834 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units,';
1835 $sql .=
' d.date_start, d.date_end,';
1836 $sql .=
' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc';
1837 $sql .=
' FROM '.MAIN_DB_PREFIX.
'propaldet as d';
1838 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (d.fk_product = p.rowid)';
1839 $sql .=
' WHERE d.fk_propal = '.((int) $this->
id);
1840 if ($only_product) {
1841 $sql .=
' AND p.fk_product_type = 0';
1846 $sql .=
' ORDER by d.rang';
1848 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1849 $result = $this->
db->query(
$sql);
1851 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
1853 $num = $this->
db->num_rows($result);
1857 $objp = $this->
db->fetch_object($result);
1861 $line->rowid = $objp->rowid;
1862 $line->id = $objp->rowid;
1863 $line->fk_propal = $objp->fk_propal;
1864 $line->fk_parent_line = $objp->fk_parent_line;
1865 $line->product_type = $objp->product_type;
1866 $line->label = $objp->custom_label;
1867 $line->desc = $objp->description;
1868 $line->description = $objp->description;
1869 $line->qty = $objp->qty;
1870 $line->vat_src_code = $objp->vat_src_code;
1871 $line->tva_tx = $objp->tva_tx;
1872 $line->localtax1_tx = $objp->localtax1_tx;
1873 $line->localtax2_tx = $objp->localtax2_tx;
1874 $line->localtax1_type = $objp->localtax1_type;
1875 $line->localtax2_type = $objp->localtax2_type;
1876 $line->subprice = $objp->subprice;
1877 $line->fk_remise_except = $objp->fk_remise_except;
1878 $line->remise_percent = $objp->remise_percent;
1879 $line->price = $objp->price;
1881 $line->info_bits = $objp->info_bits;
1882 $line->total_ht = $objp->total_ht;
1883 $line->total_tva = $objp->total_tva;
1884 $line->total_localtax1 = $objp->total_localtax1;
1885 $line->total_localtax2 = $objp->total_localtax2;
1886 $line->total_ttc = $objp->total_ttc;
1887 $line->fk_fournprice = $objp->fk_fournprice;
1888 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1889 $line->pa_ht = $marginInfos[0];
1890 $line->marge_tx = $marginInfos[1];
1891 $line->marque_tx = $marginInfos[2];
1892 $line->special_code = $objp->special_code;
1893 $line->rang = $objp->rang;
1895 $line->fk_product = $objp->fk_product;
1897 $line->ref = $objp->product_ref;
1898 $line->libelle = $objp->product_label;
1900 $line->product_ref = $objp->product_ref;
1901 $line->product_label = $objp->product_label;
1902 $line->product_desc = $objp->product_desc;
1903 $line->product_tobatch = $objp->product_tobatch;
1904 $line->product_barcode = $objp->product_barcode;
1906 $line->fk_product_type = $objp->fk_product_type;
1907 $line->fk_unit = $objp->fk_unit;
1908 $line->weight = $objp->weight;
1909 $line->weight_units = $objp->weight_units;
1910 $line->volume = $objp->volume;
1911 $line->volume_units = $objp->volume_units;
1913 $line->date_start = $this->
db->jdate($objp->date_start);
1914 $line->date_end = $this->
db->jdate($objp->date_end);
1917 $line->fk_multicurrency = $objp->fk_multicurrency;
1918 $line->multicurrency_code = $objp->multicurrency_code;
1919 $line->multicurrency_subprice = $objp->multicurrency_subprice;
1920 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
1921 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
1922 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
1924 $line->fetch_optionals();
1927 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
1929 $tmpproduct->fetch($objp->fk_product);
1930 $tmpproduct->getMultiLangs();
1932 $line->multilangs = $tmpproduct->multilangs;
1935 $this->lines[$i] = $line;
1940 $this->
db->free($result);
1944 $this->error = $this->
db->lasterror();
1956 public function valid($user, $notrigger = 0)
1960 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1965 if ($this->statut == self::STATUS_VALIDATED) {
1966 dol_syslog(get_class($this).
"::valid action abandonned: already validated", LOG_WARNING);
1970 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->creer))
1971 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)))) {
1972 $this->error =
'ErrorPermissionDenied';
1973 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
1983 $soc->fetch($this->socid);
1986 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1993 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
1994 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1995 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
", date_valid='".$this->
db->idate($now).
"', fk_user_valid=".((int) $user->id);
1998 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
1999 $resql = $this->
db->query(
$sql);
2006 if (!$error && !$notrigger) {
2008 $result = $this->
call_trigger(
'PROPAL_VALIDATE', $user);
2016 $this->oldref = $this->ref;
2019 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
2021 $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).
"'";
2022 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'propale/".$this->
db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
2023 $resql = $this->
db->query(
$sql);
2026 $this->error = $this->
db->lasterror();
2032 $dirsource = $conf->propal->multidir_output[$this->entity].
'/'.$oldref;
2033 $dirdest = $conf->propal->multidir_output[$this->entity].
'/'.$newref;
2034 if (!$error && file_exists($dirsource)) {
2035 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
2036 if (@rename($dirsource, $dirdest)) {
2039 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
2040 foreach ($listoffiles as $fileentry) {
2041 $dirsource = $fileentry[
'name'];
2042 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
2043 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
2044 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
2045 @rename($dirsource, $dirdest);
2052 $this->brouillon = 0;
2054 $this->user_valid_id = $user->id;
2055 $this->datev = $now;
2057 $this->
db->commit();
2060 $this->
db->rollback();
2079 $this->error =
'ErrorBadParameter';
2080 dol_syslog(get_class($this).
"::set_date ".$this->error, LOG_ERR);
2084 if (!empty($user->rights->propal->creer)) {
2089 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET datep = '".$this->
db->idate($date).
"'";
2093 $resql = $this->
db->query(
$sql);
2095 $this->errors[] = $this->
db->error();
2100 $this->oldcopy = clone $this;
2101 $this->date = $date;
2102 $this->datep = $date;
2105 if (!$notrigger && empty($error)) {
2115 $this->
db->commit();
2118 foreach ($this->errors as $errmsg) {
2119 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2120 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2122 $this->
db->rollback();
2142 if (!empty($user->rights->propal->creer)) {
2147 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET fin_validite = ".($date_end_validity !=
'' ?
"'".$this->db->idate($date_end_validity).
"'" :
'null');
2148 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = ".((int) self::STATUS_DRAFT);
2151 $resql = $this->
db->query(
$sql);
2153 $this->errors[] = $this->
db->error();
2159 $this->oldcopy = clone $this;
2160 $this->fin_validite = $date_end_validity;
2163 if (!$notrigger && empty($error)) {
2173 $this->
db->commit();
2176 foreach ($this->errors as $errmsg) {
2177 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2178 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2180 $this->
db->rollback();
2214 if (!empty($user->rights->propal->creer)) {
2219 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal ";
2220 $sql .=
" SET date_livraison = ".($delivery_date !=
'' ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2221 $sql .=
" WHERE rowid = ".((int) $this->
id);
2224 $resql = $this->
db->query(
$sql);
2226 $this->errors[] = $this->
db->error();
2231 $this->oldcopy = clone $this;
2232 $this->date_livraison = $delivery_date;
2233 $this->delivery_date = $delivery_date;
2236 if (!$notrigger && empty($error)) {
2246 $this->
db->commit();
2249 foreach ($this->errors as $errmsg) {
2250 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2251 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2253 $this->
db->rollback();
2273 if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) {
2278 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2279 $sql .=
" SET fk_availability = ".((int) $id);
2280 $sql .=
" WHERE rowid = ".((int) $this->
id);
2282 dol_syslog(__METHOD__.
' availability('.$id.
')', LOG_DEBUG);
2283 $resql = $this->
db->query(
$sql);
2285 $this->errors[] = $this->
db->error();
2290 $this->oldcopy = clone $this;
2291 $this->fk_availability = $id;
2292 $this->availability_id = $id;
2295 if (!$notrigger && empty($error)) {
2305 $this->
db->commit();
2308 foreach ($this->errors as $errmsg) {
2309 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2310 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2312 $this->
db->rollback();
2316 $error_str =
'Propal status do not meet requirement '.$this->statut;
2318 $this->error = $error_str;
2319 $this->errors[] = $this->error;
2336 if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) {
2341 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal ";
2342 $sql .=
" SET fk_input_reason = ".((int) $id);
2343 $sql .=
" WHERE rowid = ".((int) $this->
id);
2346 $resql = $this->
db->query(
$sql);
2348 $this->errors[] = $this->
db->error();
2354 $this->oldcopy = clone $this;
2355 $this->fk_input_reason = $id;
2356 $this->demand_reason_id = $id;
2360 if (!$notrigger && empty($error)) {
2370 $this->
db->commit();
2373 foreach ($this->errors as $errmsg) {
2374 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2375 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2377 $this->
db->rollback();
2381 $error_str =
'Propal status do not meet requirement '.$this->statut;
2383 $this->error = $error_str;
2384 $this->errors[] = $this->error;
2401 if (!empty($user->rights->propal->creer)) {
2406 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
2407 $sql .=
" WHERE rowid = ".((int) $this->
id);
2409 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
2410 $resql = $this->
db->query(
$sql);
2412 $this->errors[] = $this->
db->error();
2417 $this->oldcopy = clone $this;
2418 $this->ref_client = $ref_client;
2421 if (!$notrigger && empty($error)) {
2431 $this->
db->commit();
2434 foreach ($this->errors as $errmsg) {
2435 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2436 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2438 $this->
db->rollback();
2460 if (!empty($user->rights->propal->creer)) {
2467 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET remise_percent = ".((
float)
$remise);
2471 $resql = $this->
db->query(
$sql);
2473 $this->errors[] = $this->
db->error();
2478 $this->oldcopy = clone $this;
2479 $this->remise_percent =
$remise;
2483 if (!$notrigger && empty($error)) {
2493 $this->
db->commit();
2496 foreach ($this->errors as $errmsg) {
2497 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2498 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2500 $this->
db->rollback();
2526 if (!empty($user->rights->propal->creer)) {
2531 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2532 $sql .=
" SET remise_absolue = ".((float)
$remise);
2536 $resql = $this->
db->query(
$sql);
2538 $this->errors[] = $this->
db->error();
2543 $this->oldcopy = clone $this;
2547 if (!$notrigger && empty($error)) {
2557 $this->
db->commit();
2560 foreach ($this->errors as $errmsg) {
2561 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2562 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2564 $this->
db->rollback();
2587 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2588 $sql .=
" SET fk_statut = ".((int) $status).
",";
2589 if (!empty(
$note)) {
2590 $sql .=
" note_private = '".$this->db->escape(
$note).
"',";
2592 $sql .=
" date_cloture=NULL, fk_user_cloture=NULL";
2593 $sql .=
" WHERE rowid = ".((int) $this->
id);
2597 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
2598 $resql = $this->
db->query(
$sql);
2601 $this->errors[] =
"Error ".$this->db->lasterror();
2616 if (!empty($this->errors)) {
2617 foreach ($this->errors as $errmsg) {
2618 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2619 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2622 $this->
db->rollback();
2625 $this->statut = $status;
2626 $this->status = $status;
2628 $this->
db->commit();
2644 global $langs,$conf;
2653 if (empty($conf->global->PROPALE_KEEP_OLD_SIGNATURE_INFO)) {
2654 $date_signature = $now;
2655 $fk_user_signature = $user->id;
2657 $this->
info($this->
id);
2658 if (!isset($this->date_signature) || $this->date_signature ==
'') {
2659 $date_signature = $now;
2660 $fk_user_signature = $user->id;
2662 $date_signature = $this->date_signature;
2663 $fk_user_signature = $this->user_signature->id;
2667 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2668 $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;
2669 $sql .=
" WHERE rowid = ".((int) $this->
id);
2671 $resql = $this->
db->query(
$sql);
2674 $modelpdf = !empty($conf->global->PROPALE_ADDON_PDF_ODT_CLOSED) ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
2675 $trigger_name =
'PROPAL_CLOSE_REFUSED';
2677 if ($status == self::STATUS_SIGNED) {
2678 $trigger_name =
'PROPAL_CLOSE_SIGNED';
2679 $modelpdf = !empty($conf->global->PROPALE_ADDON_PDF_ODT_TOBILL) ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->model_pdf;
2683 $soc->id = $this->socid;
2684 $result = $soc->set_as_client();
2687 $this->error=$this->
db->lasterror();
2688 $this->
db->rollback();
2693 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2695 $outputlangs = $langs;
2697 $outputlangs =
new Translate(
"", $conf);
2698 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2699 $outputlangs->setDefaultLang($newlang);
2703 $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
2704 $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
2705 $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
2708 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2712 $this->oldcopy= clone $this;
2713 $this->statut = $status;
2714 $this->status = $status;
2715 $this->date_signature = $date_signature;
2716 $this->note_private = $newprivatenote;
2719 if (!$notrigger && empty($error)) {
2729 $this->
db->commit();
2732 $this->statut = $this->oldcopy->statut;
2733 $this->status = $this->oldcopy->statut;
2734 $this->date_signature = $this->oldcopy->date_signature;
2735 $this->note_private = $this->oldcopy->note_private;
2737 $this->
db->rollback();
2741 $this->error = $this->
db->lasterror();
2742 $this->
db->rollback();
2757 global $conf, $langs;
2764 $triggerName =
'PROPAL_CLASSIFY_BILLED';
2770 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal SET fk_statut = '.self::STATUS_BILLED.
", ";
2771 $sql .=
" note_private = '".$this->db->escape($newprivatenote).
"', date_cloture='".$this->
db->idate($now).
"', fk_user_cloture=".((int) $user->id);
2772 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_SIGNED);
2775 $resql = $this->
db->query(
$sql);
2777 $this->errors[] = $this->
db->error();
2780 $num = $this->
db->affected_rows($resql);
2784 $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
2786 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2788 $outputlangs = $langs;
2790 $outputlangs =
new Translate(
"", $conf);
2791 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2792 $outputlangs->setDefaultLang($newlang);
2796 $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
2797 $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
2798 $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
2801 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2804 $this->oldcopy = clone $this;
2806 $this->date_cloture = $now;
2807 $this->note_private = $newprivatenote;
2810 if (!$notrigger && empty($error)) {
2820 $this->
db->commit();
2823 foreach ($this->errors as $errmsg) {
2824 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2825 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2827 $this->
db->rollback();
2846 if ($this->statut <= self::STATUS_DRAFT) {
2850 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
2854 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2855 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2856 $sql .=
", online_sign_ip = NULL , online_sign_name = NULL";
2857 $sql .=
" WHERE rowid = ".((int) $this->
id);
2859 $resql = $this->
db->query(
$sql);
2861 $this->errors[] = $this->
db->error();
2866 $this->oldcopy = clone $this;
2869 if (!$notrigger && empty($error)) {
2880 $this->brouillon = 1;
2882 $this->
db->commit();
2885 foreach ($this->errors as $errmsg) {
2886 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2887 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2889 $this->
db->rollback();
2909 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datep', $sortorder =
'DESC')
2916 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
2917 $sql .=
" p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
2918 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
2919 if (empty($user->rights->societe->client->voir) && !$socid) {
2920 $sql .=
", sc.fk_soc, sc.fk_user";
2922 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"propal as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
2923 if (empty($user->rights->societe->client->voir) && !$socid) {
2924 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
2926 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
2927 $sql .=
" AND p.fk_soc = s.rowid";
2928 $sql .=
" AND p.fk_statut = c.id";
2929 if (empty($user->rights->societe->client->voir) && !$socid) {
2930 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2933 $sql .=
" AND s.rowid = ".((int) $socid);
2936 $sql .=
" AND p.fk_statut = ".self::STATUS_DRAFT;
2938 if ($notcurrentuser > 0) {
2939 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
2941 $sql .= $this->
db->order($sortfield, $sortorder);
2942 $sql .= $this->
db->plimit($limit, $offset);
2944 $result = $this->
db->query(
$sql);
2946 $num = $this->
db->num_rows($result);
2950 $obj = $this->
db->fetch_object($result);
2952 if ($shortlist == 1) {
2953 $ga[$obj->propalid] = $obj->ref;
2954 } elseif ($shortlist == 2) {
2955 $ga[$obj->propalid] = $obj->ref.
' ('.$obj->name.
')';
2957 $ga[$i][
'id'] = $obj->propalid;
2958 $ga[$i][
'ref'] = $obj->ref;
2959 $ga[$i][
'name'] = $obj->name;
2993 $linkedInvoices = array();
2996 foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
2999 foreach ($objectid as $key => $object) {
3001 if ($objecttype ==
'facture') {
3002 $linkedInvoices[] = $object;
3006 foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
3007 foreach ($subobjectid as $subkey => $subobject) {
3008 if ($subobjecttype ==
'facture') {
3009 $linkedInvoices[] = $subobject;
3017 if (count($linkedInvoices) > 0) {
3018 $sql =
"SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye";
3019 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
3020 $sql .=
" WHERE rowid IN (".$this->db->sanitize(implode(
',', $linkedInvoices)).
")";
3022 dol_syslog(get_class($this).
"::InvoiceArrayList", LOG_DEBUG);
3023 $resql = $this->
db->query(
$sql);
3026 $tab_sqlobj = array();
3027 $nump = $this->
db->num_rows($resql);
3028 for ($i = 0; $i < $nump; $i++) {
3029 $sqlobj = $this->
db->fetch_object($resql);
3030 $tab_sqlobj[] = $sqlobj;
3032 $this->
db->free($resql);
3034 $nump = count($tab_sqlobj);
3038 while ($i < $nump) {
3039 $obj = array_shift($tab_sqlobj);
3062 public function delete($user, $notrigger = 0)
3065 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3081 if (!$error && !empty($this->table_element_line)) {
3082 $tabletodelete = $this->table_element_line;
3083 $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).
")";
3084 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3085 if (!$this->
db->query($sqlef) || !$this->
db->query(
$sql)) {
3087 $this->error = $this->
db->lasterror();
3088 $this->errors[] = $this->error;
3089 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3114 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3120 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3121 $res = $this->
db->query(
$sql);
3124 $this->error = $this->
db->lasterror();
3125 $this->errors[] = $this->error;
3126 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3141 if ($conf->propal->multidir_output[$this->entity] && !empty($this->
ref)) {
3142 $dir = $conf->propal->multidir_output[$this->entity].
"/".$ref;
3143 $file = $dir.
"/".$ref.
".pdf";
3144 if (file_exists($file)) {
3148 $this->error =
'ErrorFailToDeleteFile';
3149 $this->errors[] = $this->error;
3150 $this->
db->rollback();
3154 if (file_exists($dir)) {
3157 $this->error =
'ErrorFailToDeleteDir';
3158 $this->errors[] = $this->error;
3159 $this->
db->rollback();
3167 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3168 $this->
db->commit();
3171 $this->
db->rollback();
3188 if ($this->statut >= self::STATUS_DRAFT) {
3193 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal';
3194 $sql .=
' SET fk_availability = '.((int) $availability_id);
3195 $sql .=
' WHERE rowid='.((int) $this->
id);
3197 dol_syslog(__METHOD__.
' availability('.$availability_id.
')', LOG_DEBUG);
3198 $resql = $this->
db->query(
$sql);
3200 $this->errors[] = $this->
db->error();
3205 $this->oldcopy = clone $this;
3206 $this->availability_id = $availability_id;
3209 if (!$notrigger && empty($error)) {
3219 $this->
db->commit();
3222 foreach ($this->errors as $errmsg) {
3223 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3224 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3226 $this->
db->rollback();
3230 $error_str =
'Propal status do not meet requirement '.$this->statut;
3232 $this->error = $error_str;
3233 $this->errors[] = $this->error;
3252 if ($this->statut >= self::STATUS_DRAFT) {
3257 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal';
3258 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
3259 $sql .=
' WHERE rowid='.((int) $this->
id);
3261 dol_syslog(__METHOD__.
' demand_reason('.$demand_reason_id.
')', LOG_DEBUG);
3262 $resql = $this->
db->query(
$sql);
3264 $this->errors[] = $this->
db->error();
3269 $this->oldcopy = clone $this;
3270 $this->demand_reason_id = $demand_reason_id;
3273 if (!$notrigger && empty($error)) {
3283 $this->
db->commit();
3286 foreach ($this->errors as $errmsg) {
3287 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3288 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3290 $this->
db->rollback();
3294 $error_str =
'Propal status do not meet requirement '.$this->statut;
3296 $this->error = $error_str;
3297 $this->errors[] = $this->error;
3311 $sql =
"SELECT c.rowid, ";
3312 $sql .=
" c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,";
3313 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
3314 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as c";
3315 $sql .=
" WHERE c.rowid = ".((int) $id);
3317 $result = $this->
db->query(
$sql);
3320 if ($this->
db->num_rows($result)) {
3321 $obj = $this->
db->fetch_object($result);
3323 $this->
id = $obj->rowid;
3325 $this->date_creation = $this->
db->jdate($obj->datec);
3326 $this->date_validation = $this->
db->jdate($obj->datev);
3327 $this->date_signature = $this->
db->jdate($obj->date_signature);
3328 $this->date_cloture = $this->
db->jdate($obj->date_cloture);
3330 $cuser =
new User($this->
db);
3331 $cuser->fetch($obj->fk_user_author);
3332 $this->user_creation = $cuser;
3334 if ($obj->fk_user_valid) {
3335 $vuser =
new User($this->
db);
3336 $vuser->fetch($obj->fk_user_valid);
3337 $this->user_validation = $vuser;
3340 if ($obj->fk_user_signature) {
3341 $user_signature =
new User($this->
db);
3342 $user_signature->fetch($obj->fk_user_signature);
3343 $this->user_signature = $user_signature;
3346 if ($obj->fk_user_cloture) {
3347 $cluser =
new User($this->
db);
3348 $cluser->fetch($obj->fk_user_cloture);
3349 $this->user_cloture = $cluser;
3352 $this->
db->free($result);
3367 return $this->
LibStatut($this->statut, $mode);
3381 global $conf, $hookmanager;
3384 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3386 $langs->load(
"propal");
3387 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraft");
3388 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidated");
3389 $this->labelStatus[2] = $langs->transnoentitiesnoconv(
"PropalStatusSigned");
3390 $this->labelStatus[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSigned");
3391 $this->labelStatus[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilled");
3392 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraftShort");
3393 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidatedShort");
3394 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv(
"PropalStatusSignedShort");
3395 $this->labelStatusShort[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSignedShort");
3396 $this->labelStatusShort[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilledShort");
3400 if ($status == self::STATUS_DRAFT) {
3401 $statusType =
'status0';
3402 } elseif ($status == self::STATUS_VALIDATED) {
3403 $statusType =
'status1';
3404 } elseif ($status == self::STATUS_SIGNED) {
3405 $statusType =
'status4';
3406 } elseif ($status == self::STATUS_NOTSIGNED) {
3407 $statusType =
'status9';
3408 } elseif ($status == self::STATUS_BILLED) {
3409 $statusType =
'status6';
3413 $parameters = array(
'status' => $status,
'mode' => $mode);
3414 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3417 return $hookmanager->resPrint;
3420 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3435 global $conf, $langs;
3439 $sql =
"SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
3440 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3441 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3442 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
3443 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3447 if ($mode ==
'opened') {
3448 $sql .=
" AND p.fk_statut = ".self::STATUS_VALIDATED;
3450 if ($mode ==
'signed') {
3451 $sql .=
" AND p.fk_statut = ".self::STATUS_SIGNED;
3454 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3457 $resql = $this->
db->query(
$sql);
3459 $langs->load(
"propal");
3464 $label = $labelShort =
'';
3465 if ($mode ==
'opened') {
3466 $delay_warning = $conf->propal->cloture->warning_delay;
3468 $label = $langs->transnoentitiesnoconv(
"PropalsToClose");
3469 $labelShort = $langs->transnoentitiesnoconv(
"ToAcceptRefuse");
3471 if ($mode ==
'signed') {
3472 $delay_warning = $conf->propal->facturation->warning_delay;
3474 $label = $langs->trans(
"PropalsToBill");
3475 $labelShort = $langs->trans(
"ToBill");
3479 $response->warning_delay = $delay_warning / 60 / 60 / 24;
3480 $response->label = $label;
3481 $response->labelShort = $labelShort;
3482 $response->url = DOL_URL_ROOT.
'/comm/propal/list.php?search_status='.$status.
'&mainmenu=commercial&leftmenu=propals';
3483 $response->url_late = DOL_URL_ROOT.
'/comm/propal/list.php?search_status='.$status.
'&mainmenu=commercial&leftmenu=propals&sortfield=p.datep&sortorder=asc';
3487 while ($obj = $this->
db->fetch_object($resql)) {
3488 $response->nbtodo++;
3489 $response->total += $obj->total_ht;
3491 if ($mode ==
'opened') {
3492 $datelimit = $this->
db->jdate($obj->datefin);
3493 if ($datelimit < ($now - $delay_warning)) {
3494 $response->nbtodolate++;
3503 $this->error = $this->
db->error();
3518 global $conf, $langs;
3523 $sql =
"SELECT rowid";
3524 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3525 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3526 $sql .= $this->
db->plimit(100);
3528 $resql = $this->
db->query(
$sql);
3530 $num_prods = $this->
db->num_rows($resql);
3532 while ($i < $num_prods) {
3534 $row = $this->
db->fetch_row($resql);
3535 $prodids[$i] = $row[0];
3541 $this->
ref =
'SPECIMEN';
3542 $this->ref_client =
'NEMICEPS';
3543 $this->specimen = 1;
3545 $this->date = time();
3546 $this->fin_validite = $this->date + 3600 * 24 * 30;
3547 $this->cond_reglement_id = 1;
3548 $this->cond_reglement_code =
'RECEP';
3549 $this->mode_reglement_id = 7;
3550 $this->mode_reglement_code =
'CHQ';
3551 $this->availability_id = 1;
3552 $this->availability_code =
'AV_NOW';
3553 $this->demand_reason_id = 1;
3554 $this->demand_reason_code =
'SRC_00';
3555 $this->note_public =
'This is a comment (public)';
3556 $this->note_private =
'This is a comment (private)';
3558 $this->multicurrency_tx = 1;
3559 $this->multicurrency_code = $conf->currency;
3564 while ($xnbp < $nbp) {
3566 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3568 $line->subprice = 100;
3571 $line->localtax1_tx = 0;
3572 $line->localtax2_tx = 0;
3574 $line->total_ht = 50;
3575 $line->total_ttc = 60;
3576 $line->total_tva = 10;
3577 $line->remise_percent = 50;
3579 $line->total_ht = 100;
3580 $line->total_ttc = 120;
3581 $line->total_tva = 20;
3582 $line->remise_percent = 00;
3585 if ($num_prods > 0) {
3586 $prodid = mt_rand(1, $num_prods);
3587 $line->fk_product = $prodids[$prodid];
3588 $line->product_ref =
'SPECIMEN';
3591 $this->lines[$xnbp] = $line;
3593 $this->total_ht += $line->total_ht;
3594 $this->total_tva += $line->total_tva;
3595 $this->total_ttc += $line->total_ttc;
3612 $this->nb = array();
3615 $sql =
"SELECT count(p.rowid) as nb";
3616 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3617 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3618 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3619 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3620 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3623 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'propal').
")";
3625 $resql = $this->
db->query(
$sql);
3628 while ($obj = $this->
db->fetch_object($resql)) {
3629 $this->nb[
"proposals"] = $obj->nb;
3631 $this->
db->free($resql);
3635 $this->error = $this->
db->error();
3650 global $conf, $langs;
3651 $langs->load(
"propal");
3653 $classname = $conf->global->PROPALE_ADDON;
3655 if (!empty($classname)) {
3658 $file = $classname.
".php";
3661 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
3662 foreach ($dirmodels as $reldir) {
3666 $mybool |= @include_once $dir.$file;
3674 $obj =
new $classname();
3676 $numref = $obj->getNextValue($soc, $this);
3678 if ($numref !=
"") {
3681 $this->error = $obj->error;
3686 $langs->load(
"errors");
3687 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Proposal"));
3700 global $conf, $langs, $user;
3704 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
3705 return [
'optimize' => $langs->trans(
"Proposal")];
3707 if ($user->hasRight(
'propal',
'lire')) {
3708 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Proposal").
'</u>';
3709 if (isset($this->statut)) {
3710 $datas[
'status'] =
' '.$this->getLibStatut(5);
3712 if (!empty($this->
ref)) {
3713 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3715 if (!empty($this->ref_client)) {
3716 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$this->ref_client;
3718 if (!empty($this->total_ht)) {
3719 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
3721 if (!empty($this->total_tva)) {
3722 $datas[
'vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
3724 if (!empty($this->total_ttc)) {
3725 $datas[
'amountttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
3727 if (!empty($this->date)) {
3728 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
3730 if (!empty($this->delivery_date)) {
3731 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3749 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1)
3751 global $langs, $conf, $user, $hookmanager;
3753 if (!empty($conf->dol_no_mouse_hover)) {
3760 'objecttype' => $this->element,
3761 'option' => $option,
3763 $classfortooltip =
'classfortooltip';
3766 $classfortooltip =
'classforajaxtooltip';
3767 $dataparams =
' data-params='.json_encode($params);
3773 if ($user->rights->propal->lire) {
3774 if ($option ==
'') {
3775 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3776 } elseif ($option ==
'compta') {
3777 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3778 } elseif ($option ==
'expedition') {
3779 $url = DOL_URL_ROOT.
'/expedition/propal.php?id='.$this->
id.$get_params;
3780 } elseif ($option ==
'document') {
3781 $url = DOL_URL_ROOT.
'/comm/propal/document.php?id='.$this->
id.$get_params;
3784 if ($option !=
'nolink') {
3786 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3787 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3788 $add_save_lastsearch_values = 1;
3790 if ($add_save_lastsearch_values) {
3791 $url .=
'&save_lastsearch_values=1';
3797 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
3798 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
3799 $label = $langs->trans(
"Proposal");
3800 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3802 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
3803 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
3806 $linkstart =
'<a href="'.$url.
'"';
3807 $linkstart .= $linkclose.
'>';
3810 $result .= $linkstart;
3812 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
3814 if ($withpicto != 2) {
3815 $result .= $this->ref;
3817 $result .= $linkend;
3819 if ($addlinktonotes >= 0) {
3822 if ($addlinktonotes == 0) {
3823 if (!empty($this->note_private) || !empty($this->note_public)) {
3824 $txttoshow = $langs->trans(
'ViewPrivateNote');
3826 } elseif ($addlinktonotes == 1) {
3827 if (!empty($this->note_private)) {
3830 } elseif ($addlinktonotes == 2) {
3831 if (!empty($this->note_public)) {
3834 } elseif ($addlinktonotes == 3) {
3835 if ($user->socid > 0) {
3836 if (!empty($this->note_public)) {
3840 if (!empty($this->note_public)) {
3843 if (!empty($this->note_private)) {
3844 if (!empty($txttoshow)) {
3845 $txttoshow .=
'<br><br>';
3853 $result .=
' <span class="note inline-block">';
3854 $result .=
'<a href="'.DOL_URL_ROOT.
'/comm/propal/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($txttoshow).
'">';
3857 $result .=
'</span>';
3862 $hookmanager->initHooks(array($this->element .
'dao'));
3863 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
3864 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3866 $result = $hookmanager->resPrint;
3868 $result .= $hookmanager->resPrint;
3895 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3897 global $conf, $langs;
3899 $langs->load(
"propale");
3900 $outputlangs->load(
"products");
3905 if ($this->model_pdf) {
3906 $modele = $this->model_pdf;
3907 } elseif (!empty($conf->global->PROPALE_ADDON_PDF)) {
3908 $modele = $conf->global->PROPALE_ADDON_PDF;
3912 $modelpath =
"core/modules/propale/doc/";
3914 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3961 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3962 $return .=
'<div class="info-box info-box-sm">';
3963 $return .=
'<span class="info-box-icon bg-infobox-action">';
3966 $return .=
'</span>';
3967 $return .=
'<div class="info-box-content">';
3968 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3969 if (property_exists($this,
'fk_project')) {
3970 $return .=
'<span class="info-box-ref"> | '.$this->fk_project.
'</span>';
3972 if (property_exists($this,
'author')) {
3973 $return .=
'<br><span class="info-box-label">'.$this->author.
'</span>';
3975 if (property_exists($this,
'total_ht')) {
3976 $return .=
'<br><span class="" >'.$langs->trans(
"AmountHT").
' : </span><span class="info-box-label amount">'.
price($this->total_ht).
'</span>';
3978 if (method_exists($this,
'getLibStatut')) {
3979 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).
'</div>';
3981 $return .=
'</div>';
3982 $return .=
'</div>';
3983 $return .=
'</div>';
3996 public $element =
'propaldet';
4001 public $table_element =
'propaldet';
4007 public $fk_parent_line;
4025 public $vat_src_code;
4028 public $remise_percent;
4029 public $fk_remise_except;
4033 public $fk_fournprice;
4038 public $special_code;
4043 public $info_bits = 0;
4072 public $product_ref;
4087 public $product_label;
4092 public $product_desc;
4098 public $product_tobatch;
4104 public $product_barcode;
4106 public $localtax1_tx;
4107 public $localtax2_tx;
4108 public $localtax1_type;
4109 public $localtax2_type;
4110 public $total_localtax1;
4111 public $total_localtax2;
4116 public $skip_update_total;
4119 public $fk_multicurrency;
4120 public $multicurrency_code;
4121 public $multicurrency_subprice;
4122 public $multicurrency_total_ht;
4123 public $multicurrency_total_tva;
4124 public $multicurrency_total_ttc;
4145 $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,';
4146 $sql .=
' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
4147 $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,';
4148 $sql .=
' pd.fk_unit,';
4149 $sql .=
' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
4150 $sql .=
' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
4151 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
4152 $sql .=
' pd.date_start, pd.date_end, pd.product_type';
4153 $sql .=
' FROM '.MAIN_DB_PREFIX.
'propaldet as pd';
4154 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON pd.fk_product = p.rowid';
4155 $sql .=
' WHERE pd.rowid = '.((int) $rowid);
4157 $result = $this->
db->query(
$sql);
4159 $objp = $this->
db->fetch_object($result);
4162 $this->
id = $objp->rowid;
4163 $this->
rowid = $objp->rowid;
4164 $this->fk_propal = $objp->fk_propal;
4165 $this->fk_parent_line = $objp->fk_parent_line;
4166 $this->label = $objp->custom_label;
4167 $this->desc = $objp->description;
4168 $this->qty = $objp->qty;
4169 $this->
price = $objp->price;
4170 $this->subprice = $objp->subprice;
4171 $this->vat_src_code = $objp->vat_src_code;
4172 $this->tva_tx = $objp->tva_tx;
4173 $this->remise = $objp->remise;
4174 $this->remise_percent = $objp->remise_percent;
4175 $this->fk_remise_except = $objp->fk_remise_except;
4176 $this->fk_product = $objp->fk_product;
4177 $this->info_bits = $objp->info_bits;
4179 $this->total_ht = $objp->total_ht;
4180 $this->total_tva = $objp->total_tva;
4181 $this->total_ttc = $objp->total_ttc;
4183 $this->fk_fournprice = $objp->fk_fournprice;
4185 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
4186 $this->pa_ht = $marginInfos[0];
4187 $this->marge_tx = $marginInfos[1];
4188 $this->marque_tx = $marginInfos[2];
4190 $this->special_code = $objp->special_code;
4191 $this->product_type = $objp->product_type;
4192 $this->rang = $objp->rang;
4194 $this->
ref = $objp->product_ref;
4195 $this->product_ref = $objp->product_ref;
4196 $this->libelle = $objp->product_label;
4197 $this->product_label = $objp->product_label;
4198 $this->product_desc = $objp->product_desc;
4199 $this->fk_unit = $objp->fk_unit;
4201 $this->date_start = $this->
db->jdate($objp->date_start);
4202 $this->date_end = $this->
db->jdate($objp->date_end);
4205 $this->fk_multicurrency = $objp->fk_multicurrency;
4206 $this->multicurrency_code = $objp->multicurrency_code;
4207 $this->multicurrency_subprice = $objp->multicurrency_subprice;
4208 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
4209 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
4210 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
4214 $this->
db->free($result);
4233 global $conf, $user;
4237 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
4239 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht ==
'');
4242 if (empty($this->tva_tx)) {
4245 if (empty($this->localtax1_tx)) {
4246 $this->localtax1_tx = 0;
4248 if (empty($this->localtax2_tx)) {
4249 $this->localtax2_tx = 0;
4251 if (empty($this->localtax1_type)) {
4252 $this->localtax1_type = 0;
4254 if (empty($this->localtax2_type)) {
4255 $this->localtax2_type = 0;
4257 if (empty($this->total_localtax1)) {
4258 $this->total_localtax1 = 0;
4260 if (empty($this->total_localtax2)) {
4261 $this->total_localtax2 = 0;
4263 if (empty($this->rang)) {
4266 if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
4267 $this->remise_percent = 0;
4269 if (empty($this->info_bits)) {
4270 $this->info_bits = 0;
4272 if (empty($this->special_code)) {
4273 $this->special_code = 0;
4275 if (empty($this->fk_parent_line)) {
4276 $this->fk_parent_line = 0;
4278 if (empty($this->fk_fournprice)) {
4279 $this->fk_fournprice = 0;
4281 if (!is_numeric($this->qty)) {
4284 if (empty($this->pa_ht)) {
4287 if (empty($this->multicurrency_subprice)) {
4288 $this->multicurrency_subprice = 0;
4290 if (empty($this->multicurrency_total_ht)) {
4291 $this->multicurrency_total_ht = 0;
4293 if (empty($this->multicurrency_total_tva)) {
4294 $this->multicurrency_total_tva = 0;
4296 if (empty($this->multicurrency_total_ttc)) {
4297 $this->multicurrency_total_ttc = 0;
4301 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
4302 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
4305 $this->pa_ht = $result;
4310 if ($this->product_type < 0) {
4317 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'propaldet';
4318 $sql .=
' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
4319 $sql .=
' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
4320 $sql .=
' subprice, remise_percent, ';
4321 $sql .=
' info_bits, ';
4322 $sql .=
' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
4323 $sql .=
' fk_unit,';
4324 $sql .=
' date_start, date_end';
4325 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
4326 $sql .=
" VALUES (".$this->fk_propal.
",";
4327 $sql .=
" ".($this->fk_parent_line > 0 ?
"'".$this->db->escape($this->fk_parent_line).
"'" :
"null").
",";
4328 $sql .=
" ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
4329 $sql .=
" '".$this->db->escape($this->desc).
"',";
4330 $sql .=
" ".($this->fk_product ?
"'".$this->db->escape($this->fk_product).
"'" :
"null").
",";
4331 $sql .=
" '".$this->db->escape($this->product_type).
"',";
4332 $sql .=
" ".($this->fk_remise_except ?
"'".$this->db->escape($this->fk_remise_except).
"'" :
"null").
",";
4333 $sql .=
" ".price2num($this->qty,
'MS').
",";
4334 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4335 $sql .=
" ".price2num($this->tva_tx).
",";
4336 $sql .=
" ".price2num($this->localtax1_tx).
",";
4337 $sql .=
" ".price2num($this->localtax2_tx).
",";
4338 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4339 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4340 $sql .=
" ".(price2num($this->subprice) !==
'' ?
price2num($this->subprice,
'MU') :
"null").
",";
4341 $sql .=
" ".price2num($this->remise_percent, 3).
",";
4342 $sql .=
" ".(isset($this->info_bits) ? ((int) $this->info_bits) :
"null").
",";
4343 $sql .=
" ".price2num($this->total_ht,
'MT').
",";
4344 $sql .=
" ".price2num($this->total_tva,
'MT').
",";
4345 $sql .=
" ".price2num($this->total_localtax1,
'MT').
",";
4346 $sql .=
" ".price2num($this->total_localtax2,
'MT').
",";
4347 $sql .=
" ".price2num($this->total_ttc,
'MT').
",";
4348 $sql .=
" ".(!empty($this->fk_fournprice) ?
"'".$this->db->escape($this->fk_fournprice).
"'" :
"null").
",";
4349 $sql .=
" ".(isset($this->pa_ht) ?
"'".price2num($this->pa_ht).
"'" :
"null").
",";
4350 $sql .=
' '.((int) $this->special_code).
',';
4351 $sql .=
' '.((int) $this->rang).
',';
4352 $sql .=
' '.(empty($this->fk_unit) ?
'NULL' : ((int) $this->fk_unit)).
',';
4353 $sql .=
" ".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
',';
4354 $sql .=
" ".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4355 $sql .=
", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) :
'null');
4356 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4357 $sql .=
", ".price2num($this->multicurrency_subprice,
'CU');
4358 $sql .=
", ".price2num($this->multicurrency_total_ht,
'CT');
4359 $sql .=
", ".price2num($this->multicurrency_total_tva,
'CT');
4360 $sql .=
", ".price2num($this->multicurrency_total_ttc,
'CT');
4363 dol_syslog(get_class($this).
'::insert', LOG_DEBUG);
4364 $resql = $this->
db->query(
$sql);
4366 $this->
rowid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'propaldet');
4369 $this->
id = $this->rowid;
4376 if (!$error && !$notrigger) {
4378 $result = $this->
call_trigger(
'LINEPROPAL_INSERT', $user);
4380 $this->
db->rollback();
4386 $this->
db->commit();
4389 $this->error = $this->
db->error().
" sql=".
$sql;
4390 $this->
db->rollback();
4402 public function delete(
User $user, $notrigger = 0)
4411 $result = $this->
call_trigger(
'LINEPROPAL_DELETE', $user);
4419 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"propaldet WHERE rowid = " . ((int) $this->
rowid);
4420 dol_syslog(
"PropaleLigne::delete", LOG_DEBUG);
4421 if ($this->
db->query(
$sql)) {
4424 $this->
id = $this->rowid;
4428 dol_syslog(get_class($this) .
"::delete error -4 " . $this->error, LOG_ERR);
4432 $this->error = $this->
db->error() .
" sql=" .
$sql;
4438 $this->
db->rollback();
4441 $this->
db->commit();
4454 global $conf, $user;
4458 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht ==
'');
4460 if (empty($this->
id) && !empty($this->
rowid)) {
4461 $this->
id = $this->rowid;
4465 if (empty($this->tva_tx)) {
4468 if (empty($this->localtax1_tx)) {
4469 $this->localtax1_tx = 0;
4471 if (empty($this->localtax2_tx)) {
4472 $this->localtax2_tx = 0;
4474 if (empty($this->total_localtax1)) {
4475 $this->total_localtax1 = 0;
4477 if (empty($this->total_localtax2)) {
4478 $this->total_localtax2 = 0;
4480 if (empty($this->localtax1_type)) {
4481 $this->localtax1_type = 0;
4483 if (empty($this->localtax2_type)) {
4484 $this->localtax2_type = 0;
4486 if (empty($this->marque_tx)) {
4487 $this->marque_tx = 0;
4489 if (empty($this->marge_tx)) {
4490 $this->marge_tx = 0;
4492 if (empty($this->
price)) {
4495 if (empty($this->remise_percent)) {
4496 $this->remise_percent = 0;
4498 if (empty($this->info_bits)) {
4499 $this->info_bits = 0;
4501 if (empty($this->special_code)) {
4502 $this->special_code = 0;
4504 if (empty($this->fk_parent_line)) {
4505 $this->fk_parent_line = 0;
4507 if (empty($this->fk_fournprice)) {
4508 $this->fk_fournprice = 0;
4510 if (empty($this->subprice)) {
4511 $this->subprice = 0;
4513 if (empty($this->pa_ht)) {
4518 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
4519 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
4522 $this->pa_ht = $result;
4529 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propaldet SET";
4530 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4531 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
4532 $sql .=
", product_type=".$this->product_type;
4533 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4534 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4535 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
4536 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
4537 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4538 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4539 $sql .=
", qty='".price2num($this->qty).
"'";
4540 $sql .=
", subprice=".price2num($this->subprice);
4541 $sql .=
", remise_percent=".price2num($this->remise_percent);
4544 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4545 if (empty($this->skip_update_total)) {
4546 $sql .=
", total_ht=".price2num($this->total_ht);
4547 $sql .=
", total_tva=".price2num($this->total_tva);
4548 $sql .=
", total_ttc=".price2num($this->total_ttc);
4549 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
4550 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
4552 $sql .=
", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ?
"'".$this->db->escape($this->fk_fournprice).
"'" :
"null");
4553 $sql .=
", buy_price_ht=".price2num($this->pa_ht);
4554 if (strlen($this->special_code)) {
4555 $sql .=
", special_code=".$this->special_code;
4557 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line :
"null");
4558 if (!empty($this->rang)) {
4559 $sql .=
", rang=".((int) $this->rang);
4561 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4562 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4563 $sql .=
", fk_unit=".(!$this->fk_unit ?
'NULL' : $this->fk_unit);
4566 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4567 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4568 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4569 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4571 $sql .=
" WHERE rowid = ".((int) $this->
id);
4573 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
4574 $resql = $this->
db->query(
$sql);
4583 if (!$error && !$notrigger) {
4585 $result = $this->
call_trigger(
'LINEPROPAL_MODIFY', $user);
4587 $this->
db->rollback();
4593 $this->
db->commit();
4596 $this->error = $this->
db->error();
4597 $this->
db->rollback();
4615 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propaldet SET";
4616 $sql .=
" total_ht=".price2num($this->total_ht,
'MT');
4617 $sql .=
",total_tva=".price2num($this->total_tva,
'MT');
4618 $sql .=
",total_ttc=".price2num($this->total_ttc,
'MT');
4619 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
4621 dol_syslog(
"PropaleLigne::update_total", LOG_DEBUG);
4623 $resql = $this->
db->query(
$sql);
4625 $this->
db->commit();
4628 $this->error = $this->
db->error();
4629 $this->
db->rollback();