43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
44require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
45require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/margin/lib/margins.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
66 public $element =
'propal';
71 public $table_element =
'propal';
76 public $table_element_line =
'propaldet';
81 public $fk_element =
'fk_propal';
86 public $picto =
'propal';
92 public $restrictiononfksoc = 1;
124 public $ref_customer;
155 public $date_creation;
166 public $date_validation;
171 public $date_signature;
176 public $user_signature;
192 public $delivery_date;
195 public $fin_validite;
197 public $user_author_id;
215 public $cond_reglement_code;
216 public $cond_reglement;
217 public $cond_reglement_doc;
219 public $mode_reglement_code;
220 public $mode_reglement;
222 public $deposit_percent;
230 public $address_type;
236 public $availability_id;
243 public $fk_availability;
248 public $availability_code;
253 public $availability;
255 public $duree_validite;
257 public $demand_reason_id;
258 public $demand_reason_code;
259 public $demand_reason;
261 public $warehouse_id;
263 public $extraparams = array();
268 public $lines = array();
275 public $labelStatus = array();
276 public $labelStatusShort = array();
307 public $fields = array(
308 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
309 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
310 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 20),
311 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 22),
312 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 40),
313 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'position' => 23),
314 '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),
315 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
316 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
317 'datep' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => -1,
'position' => 60),
318 'fin_validite' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' => 1,
'visible' => -1,
'position' => 65),
319 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 70),
320 'date_cloture' => array(
'type' =>
'datetime',
'label' =>
'DateClosing',
'enabled' => 1,
'visible' => -1,
'position' => 75),
321 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 80),
322 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 85),
323 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 90),
324 'fk_user_cloture' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user cloture',
'enabled' => 1,
'visible' => -1,
'position' => 95),
325 'price' => array(
'type' =>
'double',
'label' =>
'Price',
'enabled' => 1,
'visible' => -1,
'position' => 105),
326 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 125,
'isameasure' => 1),
327 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'VAT',
'enabled' => 1,
'visible' => -1,
'position' => 130,
'isameasure' => 1),
328 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax1',
'enabled' => 1,
'visible' => -1,
'position' => 135,
'isameasure' => 1),
329 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax2',
'enabled' => 1,
'visible' => -1,
'position' => 140,
'isameasure' => 1),
330 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 145,
'isameasure' => 1),
331 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 150),
332 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 155),
333 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 160),
334 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 161),
335 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 165),
336 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 170),
337 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 175),
338 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 180),
339 'date_livraison' => array(
'type' =>
'date',
'label' =>
'DateDeliveryPlanned',
'enabled' => 1,
'visible' => -1,
'position' => 185),
340 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMethod',
'enabled' => 1,
'visible' => -1,
'position' => 190),
341 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Fk warehouse',
'enabled' =>
'isModEnabled("stock")',
'visible' => -1,
'position' => 191),
342 'fk_availability' => array(
'type' =>
'integer',
'label' =>
'Availability',
'enabled' => 1,
'visible' => -1,
'position' => 195),
343 'fk_delivery_address' => array(
'type' =>
'integer',
'label' =>
'DeliveryAddress',
'enabled' => 1,
'visible' => 0,
'position' => 200),
344 'fk_input_reason' => array(
'type' =>
'integer',
'label' =>
'InputReason',
'enabled' => 1,
'visible' => -1,
'position' => 205),
345 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 215),
346 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' =>
'$conf->incoterm->enabled',
'visible' => -1,
'position' => 220),
347 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLabel',
'enabled' =>
'$conf->incoterm->enabled',
'visible' => -1,
'position' => 225),
348 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'MulticurrencyID',
'enabled' => 1,
'visible' => -1,
'position' => 230),
349 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCurrency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
350 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240,
'isameasure' => 1),
351 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 245,
'isameasure' => 1),
352 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 250,
'isameasure' => 1),
353 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 255,
'isameasure' => 1),
354 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 260),
355 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
356 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
397 $this->ismultientitymanaged = 1;
398 $this->socid = $socid;
399 $this->
id = $propalid;
401 $this->duree_validite =
getDolGlobalInt(
'PROPALE_VALIDITY_DURATION', 0);
417 public function add_product($idproduct, $qty, $remise_percent = 0)
420 global $conf, $mysoc;
426 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
427 if ($idproduct > 0) {
428 $prod =
new Product($this->db);
429 $prod->fetch($idproduct);
431 $productdesc = $prod->description;
435 if (empty($tva_tx)) {
440 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
441 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
444 if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) {
445 $price = $prod->multiprices[$this->thirdparty->price_level];
452 $line->fk_product = $idproduct;
453 $line->desc = $productdesc;
456 $line->remise_percent = $remise_percent;
457 $line->vat_src_code = $vat_src_code;
458 $line->tva_tx = $tva_tx;
459 $line->fk_unit = $prod->fk_unit;
461 $line->info_bits = 1;
464 $this->lines[] = $line;
482 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
483 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
488 $result = $remise->fetch($idremise);
491 if ($remise->fk_facture) {
492 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
493 $this->db->rollback();
499 $line->context = $this->context;
501 $line->fk_propal = $this->id;
502 $line->fk_remise_except = $remise->id;
503 $line->desc = $remise->description;
504 $line->vat_src_code = $remise->vat_src_code;
505 $line->tva_tx = $remise->tva_tx;
506 $line->subprice = -$remise->amount_ht;
507 $line->fk_product = 0;
509 $line->remise_percent = 0;
511 $line->info_bits = 2;
514 $line->price = -$remise->amount_ht;
516 $line->total_ht = -$remise->amount_ht;
517 $line->total_tva = -$remise->amount_tva;
518 $line->total_ttc = -$remise->amount_ttc;
520 $result = $line->insert();
527 $this->db->rollback();
531 $this->error = $line->error;
532 $this->errors = $line->errors;
533 $this->db->rollback();
537 $this->db->rollback();
579 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 = array(), $fk_unit =
null, $origin =
'', $origin_id = 0, $pu_ht_devise = 0, $fk_remise_except = 0, $noupdateafterinsertline = 0)
581 global $mysoc, $conf, $langs;
583 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);
585 if ($this->
statut == self::STATUS_DRAFT) {
586 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
589 if (empty($remise_percent)) {
595 if (empty($info_bits)) {
601 if (empty($fk_parent_line) || $fk_parent_line < 0) {
605 $remise_percent =
price2num($remise_percent);
608 $pu_ht_devise =
price2num($pu_ht_devise);
610 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
616 if ($price_base_type ==
'HT') {
627 if ($date_start && $date_end && $date_start > $date_end) {
628 $langs->load(
"errors");
629 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
635 $product_type = $type;
636 if (!empty($fk_product) && $fk_product > 0) {
637 $product =
new Product($this->db);
638 $result = $product->fetch($fk_product);
639 $product_type = $product->type;
641 if (
getDolGlobalString(
'STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL') && $product_type == 0 && $product->stock_reel < $qty) {
642 $langs->load(
"errors");
643 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref);
644 $this->db->rollback();
659 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
660 $vat_src_code = $reg[1];
661 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
664 $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);
666 $total_ht = $tabprice[0];
667 $total_tva = $tabprice[1];
668 $total_ttc = $tabprice[2];
669 $total_localtax1 = $tabprice[9];
670 $total_localtax2 = $tabprice[10];
671 $pu_ht = $tabprice[3];
672 $pu_tva = $tabprice[4];
673 $pu_ttc = $tabprice[5];
676 $multicurrency_total_ht = $tabprice[16];
677 $multicurrency_total_tva = $tabprice[17];
678 $multicurrency_total_ttc = $tabprice[18];
679 $pu_ht_devise = $tabprice[19];
683 if ($ranktouse == -1) {
684 $rangmax = $this->
line_max($fk_parent_line);
685 $ranktouse = $rangmax + 1;
692 if ((
float) $remise_percent > 0) {
693 $remise = round(((
float) $pu * (
float) $remise_percent / 100), 2);
694 $price = (float) $pu - $remise;
700 $this->line->context = $this->context;
702 $this->line->fk_propal = $this->id;
703 $this->line->label = $label;
704 $this->line->desc = $desc;
705 $this->line->qty = $qty;
707 $this->line->vat_src_code = $vat_src_code;
708 $this->line->tva_tx = $txtva;
709 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
710 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
711 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
712 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
713 $this->line->fk_product = $fk_product;
714 $this->line->product_type = $type;
715 $this->line->fk_remise_except = $fk_remise_except;
716 $this->line->remise_percent = $remise_percent;
717 $this->line->subprice = $pu_ht;
718 $this->line->rang = $ranktouse;
719 $this->line->info_bits = $info_bits;
720 $this->line->total_ht = $total_ht;
721 $this->line->total_tva = $total_tva;
722 $this->line->total_localtax1 = $total_localtax1;
723 $this->line->total_localtax2 = $total_localtax2;
724 $this->line->total_ttc = $total_ttc;
725 $this->line->special_code = $special_code;
726 $this->line->fk_parent_line = $fk_parent_line;
727 $this->line->fk_unit = $fk_unit;
729 $this->line->date_start = $date_start;
730 $this->line->date_end = $date_end;
732 $this->line->fk_fournprice = $fk_fournprice;
733 $this->line->pa_ht = $pa_ht;
735 $this->line->origin_id = $origin_id;
736 $this->line->origin = $origin;
739 $this->line->fk_multicurrency = $this->fk_multicurrency;
740 $this->line->multicurrency_code = $this->multicurrency_code;
741 $this->line->multicurrency_subprice = $pu_ht_devise;
742 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
743 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
744 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
747 if (empty($qty) && empty($special_code)) {
748 $this->line->special_code = 3;
752 $this->line->price =
$price;
754 if (is_array($array_options) && count($array_options) > 0) {
755 $this->line->array_options = $array_options;
758 $result = $this->line->insert();
761 if (!empty($fk_parent_line)) {
763 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
764 $linecount = count($this->lines);
765 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
771 if (empty($noupdateafterinsertline)) {
777 return $this->line->id;
779 $this->error = $this->db->error();
780 $this->db->rollback();
784 $this->error = $this->line->error;
785 $this->errors = $this->line->errors;
786 $this->db->rollback();
790 dol_syslog(get_class($this).
"::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR);
825 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 = array(), $fk_unit =
null, $pu_ht_devise = 0, $notrigger = 0, $rang = 0)
827 global $mysoc, $langs;
829 dol_syslog(get_class($this).
"::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent,
830 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");
831 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
834 $remise_percent =
price2num($remise_percent);
837 $pu_ht_devise =
price2num($pu_ht_devise);
838 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
844 if (empty($qty) && empty($special_code)) {
847 if (!empty($qty) && $special_code == 3) {
854 if ($date_start && $date_end && $date_start > $date_end) {
855 $langs->load(
"errors");
856 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
860 if ($this->
status == self::STATUS_DRAFT) {
873 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
874 $vat_src_code = $reg[1];
875 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
880 $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);
881 $total_ht = $tabprice[0];
882 $total_tva = $tabprice[1];
883 $total_ttc = $tabprice[2];
884 $total_localtax1 = $tabprice[9];
885 $total_localtax2 = $tabprice[10];
886 $pu_ht = $tabprice[3];
887 $pu_tva = $tabprice[4];
888 $pu_ttc = $tabprice[5];
891 $multicurrency_total_ht = $tabprice[16];
892 $multicurrency_total_tva = $tabprice[17];
893 $multicurrency_total_ttc = $tabprice[18];
894 $pu_ht_devise = $tabprice[19];
899 if ((
float) $remise_percent > 0) {
900 $remise = round(((
float) $pu * (
float) $remise_percent / 100), 2);
901 $price = (float) $pu - $remise;
906 $line->fetch($rowid);
908 $staticline = clone $line;
910 $line->oldline = $staticline;
912 $this->line->context = $this->context;
913 $this->line->rang = $rang;
916 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
917 $rangmax = $this->
line_max($fk_parent_line);
918 $this->line->rang = $rangmax + 1;
921 $this->line->id = $rowid;
922 $this->line->label = $label;
923 $this->line->desc = $desc;
924 $this->line->qty = $qty;
925 $this->line->product_type = $type;
926 $this->line->vat_src_code = $vat_src_code;
927 $this->line->tva_tx = $txtva;
928 $this->line->localtax1_tx = $txlocaltax1;
929 $this->line->localtax2_tx = $txlocaltax2;
930 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
931 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
932 $this->line->remise_percent = $remise_percent;
933 $this->line->subprice = $pu_ht;
934 $this->line->info_bits = $info_bits;
936 $this->line->total_ht = $total_ht;
937 $this->line->total_tva = $total_tva;
938 $this->line->total_localtax1 = $total_localtax1;
939 $this->line->total_localtax2 = $total_localtax2;
940 $this->line->total_ttc = $total_ttc;
941 $this->line->special_code = $special_code;
942 $this->line->fk_parent_line = $fk_parent_line;
943 $this->line->skip_update_total = $skip_update_total;
944 $this->line->fk_unit = $fk_unit;
946 $this->line->fk_fournprice = $fk_fournprice;
947 $this->line->pa_ht = $pa_ht;
949 $this->line->date_start = $date_start;
950 $this->line->date_end = $date_end;
952 if (is_array($array_options) && count($array_options) > 0) {
954 foreach ($array_options as $key => $value) {
955 $this->line->array_options[$key] = $array_options[$key];
960 $this->line->multicurrency_subprice = $pu_ht_devise;
961 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
962 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
963 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
965 $result = $this->line->update($notrigger);
968 if (!empty($fk_parent_line)) {
981 $this->error = $this->line->error;
982 $this->errors = $this->line->errors;
983 $this->db->rollback();
987 dol_syslog(get_class($this).
"::updateline Erreur -2 Propal en mode incompatible pour cette action");
1004 if ($this->
statut == self::STATUS_DRAFT) {
1009 $line->context = $this->context;
1012 $line->fetch($lineid);
1014 if ($id > 0 && $line->fk_propal != $id) {
1015 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1020 $staticline = clone $line;
1021 $line->oldline = $staticline;
1023 if ($line->delete($user) > 0) {
1026 $this->db->commit();
1029 $this->error = $line->error;
1030 $this->errors = $line->errors;
1031 $this->db->rollback();
1035 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1049 public function create($user, $notrigger = 0)
1051 global $conf, $hookmanager, $mysoc;
1057 if (empty($this->date)) {
1060 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1061 if (empty($this->availability_id)) {
1062 $this->availability_id = 0;
1064 if (empty($this->demand_reason_id)) {
1065 $this->demand_reason_id = 0;
1069 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1074 if (empty($this->fk_multicurrency)) {
1075 $this->multicurrency_code = $conf->currency;
1076 $this->fk_multicurrency = 0;
1077 $this->multicurrency_tx = 1;
1081 $delivery_date = $this->delivery_date;
1088 $this->error =
"Failed to fetch company";
1089 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1094 if (!empty($this->
ref)) {
1097 $this->error =
'ErrorRefAlreadyExists';
1098 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1099 $this->db->rollback();
1104 if (empty($this->date)) {
1105 $this->error =
"Date of proposal is required";
1106 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1114 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"propal (";
1117 $sql .=
", total_tva";
1118 $sql .=
", total_ttc";
1122 $sql .=
", fk_user_author";
1123 $sql .=
", note_private";
1124 $sql .=
", note_public";
1125 $sql .=
", model_pdf";
1126 $sql .=
", fin_validite";
1127 $sql .=
", fk_cond_reglement";
1128 $sql .=
", deposit_percent";
1129 $sql .=
", fk_mode_reglement";
1130 $sql .=
", fk_account";
1131 $sql .=
", ref_client";
1132 $sql .=
", ref_ext";
1133 $sql .=
", date_livraison";
1134 $sql .=
", fk_shipping_method";
1135 $sql .=
", fk_warehouse";
1136 $sql .=
", fk_availability";
1137 $sql .=
", fk_input_reason";
1138 $sql .=
", fk_projet";
1139 $sql .=
", fk_incoterms";
1140 $sql .=
", location_incoterms";
1142 $sql .=
", fk_multicurrency";
1143 $sql .=
", multicurrency_code";
1144 $sql .=
", multicurrency_tx";
1146 $sql .=
" VALUES (";
1147 $sql .= $this->socid;
1151 $sql .=
", '".$this->db->idate($this->date).
"'";
1152 $sql .=
", '".$this->db->idate($now).
"'";
1153 $sql .=
", '(PROV)'";
1154 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
1155 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1156 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1157 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1158 $sql .=
", ".($this->fin_validite !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
"NULL");
1159 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1160 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
'NULL');
1161 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1162 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1163 $sql .=
", '".$this->db->escape($this->ref_client).
"'";
1164 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
1165 $sql .=
", ".(empty($delivery_date) ?
"NULL" :
"'".$this->db->idate($delivery_date).
"'");
1166 $sql .=
", ".($this->shipping_method_id > 0 ? $this->shipping_method_id :
'NULL');
1167 $sql .=
", ".($this->warehouse_id > 0 ? $this->warehouse_id :
'NULL');
1168 $sql .=
", ".$this->availability_id;
1169 $sql .=
", ".$this->demand_reason_id;
1170 $sql .=
", ".($this->fk_project ? $this->fk_project :
"null");
1171 $sql .=
", ".(int) $this->fk_incoterms;
1172 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1173 $sql .=
", ".setEntity($this);
1174 $sql .=
", ".(int) $this->fk_multicurrency;
1175 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1176 $sql .=
", ".(float) $this->multicurrency_tx;
1179 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1180 $resql = $this->db->query($sql);
1182 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"propal");
1185 $this->
ref =
'(PROV'.$this->id.
')';
1186 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"propal SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1188 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1189 $resql = $this->db->query($sql);
1194 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1195 $this->linked_objects = $this->linkedObjectsIds;
1199 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1200 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1201 if (is_array($tmp_origin_id)) {
1202 foreach ($tmp_origin_id as $origin_id) {
1205 $this->error = $this->db->lasterror();
1210 $origin_id = $tmp_origin_id;
1213 $this->error = $this->db->lasterror();
1225 $fk_parent_line = 0;
1226 $num = count($this->lines);
1228 for ($i = 0; $i < $num; $i++) {
1229 if (!is_object($this->lines[$i])) {
1231 $line = (object) $this->lines[$i];
1233 $line = $this->lines[$i];
1236 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1237 $fk_parent_line = 0;
1240 $vatrate = $line->tva_tx;
1241 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', $vatrate)) {
1242 $vatrate .=
' ('.$line->vat_src_code.
')';
1246 $originid = $line->origin_id;
1247 $origintype = $line->origin;
1249 $originid = $line->id;
1250 $origintype = $this->element;
1258 $line->localtax1_tx,
1259 $line->localtax2_tx,
1261 $line->remise_percent,
1265 $line->product_type,
1267 $line->special_code,
1269 $line->fk_fournprice,
1274 $line->array_options,
1285 $this->error = $this->db->error;
1291 $line->id = $result;
1294 if ($result > 0 && $line->product_type == 9) {
1295 $fk_parent_line = $result;
1325 if (!$error && !$notrigger) {
1334 $this->error = $this->db->lasterror();
1339 $this->error = $this->db->lasterror();
1344 $this->db->commit();
1345 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1348 $this->db->rollback();
1352 $this->error = $this->db->lasterror();
1353 $this->db->rollback();
1368 public function createFromClone(
User $user, $socid = 0, $forceentity =
null, $update_prices =
false, $update_desc =
false)
1370 global $conf, $hookmanager, $mysoc;
1379 $object =
new self($this->db);
1386 $objsoc =
new Societe($this->db);
1389 if (!empty($socid) && $socid !=
$object->socid) {
1390 if ($objsoc->fetch($socid) > 0) {
1392 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1393 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
null);
1394 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1395 $object->fk_delivery_address = 0;
1417 $objsoc->fetch(
$object->socid);
1421 if ($update_prices ===
true || $update_desc ===
true) {
1422 if ($objsoc->id > 0 && !empty(
$object->lines)) {
1425 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1428 foreach (
$object->lines as $line) {
1431 if ($line->fk_product > 0) {
1432 $prod =
new Product($this->db);
1433 $res = $prod->fetch($line->fk_product);
1435 if ($update_prices ===
true) {
1436 $pu_ht = $prod->price;
1438 $remise_percent = $objsoc->remise_percent;
1441 $pu_ht = $prod->multiprices[$objsoc->price_level];
1443 if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) {
1444 $tva_tx = $prod->multiprices_tva_tx[$objsoc->price_level];
1449 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $objsoc->id);
1450 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1453 if (count($prodcustprice->lines) > 0) {
1454 $pu_ht =
price($prodcustprice->lines[0]->price);
1455 $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.
' ('.$prodcustprice->lines[0]->default_vat_code.
' )' : $prodcustprice->lines[0]->tva_tx);
1456 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1457 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1463 $line->subprice = $pu_ht;
1464 $line->tva_tx = $tva_tx;
1465 $line->remise_percent = $remise_percent;
1467 if ($update_desc ===
true) {
1468 $line->desc = $prod->description;
1478 $object->entity = (!empty($forceentity) ? $forceentity :
$object->entity);
1482 $object->user_creation_id = $user->id;
1483 $object->user_validation_id = 0;
1495 $object->context[
'createfromclone'] =
'createfromclone';
1496 $result =
$object->create($user);
1498 $this->error =
$object->error;
1499 $this->errors = array_merge($this->errors,
$object->errors);
1505 if (
$object->copy_linked_contact($this,
'internal') < 0) {
1512 if ($this->socid ==
$object->socid) {
1513 if (
$object->copy_linked_contact($this,
'external') < 0) {
1521 if (is_object($hookmanager)) {
1522 $parameters = array(
'objFrom' => $this,
'clonedObj' =>
$object);
1524 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1532 unset(
$object->context[
'createfromclone']);
1536 $this->db->commit();
1539 $this->db->rollback();
1553 public function fetch($rowid, $ref =
'', $ref_ext =
'', $forceentity = 0)
1555 $sql =
"SELECT p.rowid, p.ref, p.entity, p.fk_soc";
1556 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1557 $sql .=
", p.datec";
1558 $sql .=
", p.date_signature as dates";
1559 $sql .=
", p.date_valid as datev";
1560 $sql .=
", p.datep as dp";
1561 $sql .=
", p.fin_validite as dfv";
1562 $sql .=
", p.date_livraison as delivery_date";
1563 $sql .=
", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
1564 $sql .=
", p.note_private, p.note_public";
1565 $sql .=
", p.fk_projet as fk_project, p.fk_statut";
1566 $sql .=
", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1567 $sql .=
", p.fk_delivery_address";
1568 $sql .=
", p.fk_availability";
1569 $sql .=
", p.fk_input_reason";
1570 $sql .=
", p.fk_cond_reglement";
1571 $sql .=
", p.fk_mode_reglement";
1572 $sql .=
', p.fk_account';
1573 $sql .=
", p.fk_shipping_method";
1574 $sql .=
", p.fk_warehouse";
1575 $sql .=
", p.fk_incoterms, p.location_incoterms";
1576 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1577 $sql .=
", p.tms as date_modification";
1578 $sql .=
", i.libelle as label_incoterms";
1579 $sql .=
", c.label as statut_label";
1580 $sql .=
", ca.code as availability_code, ca.label as availability";
1581 $sql .=
", dr.code as demand_reason_code, dr.label as demand_reason";
1582 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1583 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1584 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
1585 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_propalst as c ON p.fk_statut = c.id';
1586 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.
getEntity(
'c_paiement').
')';
1587 $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').
')';
1588 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON p.fk_availability = ca.rowid';
1589 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
1590 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON p.fk_incoterms = i.rowid';
1593 if (!empty($forceentity)) {
1594 $sql .=
" WHERE p.entity = ".(int) $forceentity;
1596 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
1598 $sql .=
" AND p.ref='".$this->db->escape($ref).
"'";
1601 $sql .=
" WHERE p.rowid = ".((int) $rowid);
1604 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1605 $resql = $this->db->query($sql);
1607 if ($this->db->num_rows($resql)) {
1608 $obj = $this->db->fetch_object($resql);
1610 $this->
id = $obj->rowid;
1611 $this->entity = $obj->entity;
1613 $this->
ref = $obj->ref;
1614 $this->ref_client = $obj->ref_client;
1615 $this->ref_customer = $obj->ref_client;
1616 $this->ref_ext = $obj->ref_ext;
1618 $this->total = $obj->total_ttc;
1619 $this->total_ttc = $obj->total_ttc;
1620 $this->total_ht = $obj->total_ht;
1621 $this->total_tva = $obj->total_tva;
1622 $this->total_localtax1 = $obj->localtax1;
1623 $this->total_localtax2 = $obj->localtax2;
1625 $this->socid = $obj->fk_soc;
1626 $this->thirdparty =
null;
1628 $this->fk_project = $obj->fk_project;
1629 $this->project =
null;
1631 $this->model_pdf = $obj->model_pdf;
1632 $this->last_main_doc = $obj->last_main_doc;
1633 $this->note = $obj->note_private;
1634 $this->note_private = $obj->note_private;
1635 $this->note_public = $obj->note_public;
1637 $this->
status = (int) $obj->fk_statut;
1638 $this->
statut = $this->status;
1640 $this->datec = $this->db->jdate($obj->datec);
1641 $this->datev = $this->db->jdate($obj->datev);
1642 $this->date_creation = $this->db->jdate($obj->datec);
1643 $this->date_validation = $this->db->jdate($obj->datev);
1644 $this->date_modification = $this->db->jdate($obj->date_modification);
1645 $this->date_signature = $this->db->jdate($obj->dates);
1646 $this->date = $this->db->jdate($obj->dp);
1647 $this->datep = $this->db->jdate($obj->dp);
1648 $this->fin_validite = $this->db->jdate($obj->dfv);
1649 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1650 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1651 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
1652 $this->availability_id = $obj->fk_availability;
1653 $this->availability_code = $obj->availability_code;
1655 $this->demand_reason_id = $obj->fk_input_reason;
1656 $this->demand_reason_code = $obj->demand_reason_code;
1658 $this->fk_address = $obj->fk_delivery_address;
1660 $this->mode_reglement_id = $obj->fk_mode_reglement;
1661 $this->mode_reglement_code = $obj->mode_reglement_code;
1662 $this->mode_reglement = $obj->mode_reglement;
1663 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1664 $this->cond_reglement_id = $obj->fk_cond_reglement;
1665 $this->cond_reglement_code = $obj->cond_reglement_code;
1666 $this->cond_reglement = $obj->cond_reglement;
1667 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1668 $this->deposit_percent = $obj->deposit_percent;
1670 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1672 $this->user_author_id = $obj->fk_user_author;
1673 $this->user_validation_id = $obj->fk_user_valid;
1674 $this->user_closing_id = $obj->fk_user_cloture;
1677 $this->fk_incoterms = $obj->fk_incoterms;
1678 $this->location_incoterms = $obj->location_incoterms;
1679 $this->label_incoterms = $obj->label_incoterms;
1682 $this->fk_multicurrency = $obj->fk_multicurrency;
1683 $this->multicurrency_code = $obj->multicurrency_code;
1684 $this->multicurrency_tx = $obj->multicurrency_tx;
1685 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1686 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1687 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1693 $this->db->free($resql);
1695 $this->lines = array();
1706 $this->error =
"Record Not Found";
1709 $this->error = $this->db->lasterror();
1728 if (isset($this->
ref)) {
1729 $this->
ref = trim($this->
ref);
1731 if (isset($this->ref_client)) {
1732 $this->ref_client = trim($this->ref_client);
1734 if (isset($this->note) || isset($this->note_private)) {
1735 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1737 if (isset($this->note_public)) {
1738 $this->note_public = trim($this->note_public);
1740 if (isset($this->model_pdf)) {
1741 $this->model_pdf = trim($this->model_pdf);
1743 if (isset($this->import_key)) {
1744 $this->import_key = trim($this->import_key);
1746 if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
1747 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1754 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET";
1755 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1756 $sql .=
" ref_client=".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
1757 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1758 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1759 $sql .=
" datep=".(strval($this->date) !=
'' ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1760 if (!empty($this->fin_validite)) {
1761 $sql .=
" fin_validite=".(strval($this->fin_validite) !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
'null').
",";
1763 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1764 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1765 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1766 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1767 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1768 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1769 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1770 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1771 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) ? $this->user_validation_id :
"null").
",";
1772 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1773 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1774 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1775 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1776 $sql .=
" fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id :
"null").
",";
1777 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1778 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1779 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1780 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1781 $sql .=
" WHERE rowid=".((int) $this->
id);
1785 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1786 $resql = $this->db->query($sql);
1789 $this->errors[] =
"Error ".$this->db->lasterror();
1799 if (!$error && !$notrigger) {
1810 foreach ($this->errors as $errmsg) {
1811 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1812 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1814 $this->db->rollback();
1817 $this->db->commit();
1832 public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $sqlforgedfilters =
'')
1835 $this->lines = array();
1837 $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,';
1838 $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,';
1839 $sql .=
' d.fk_unit,';
1840 $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,';
1841 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units,';
1842 $sql .=
' d.date_start, d.date_end,';
1843 $sql .=
' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc';
1844 $sql .=
' FROM '.MAIN_DB_PREFIX.
'propaldet as d';
1845 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (d.fk_product = p.rowid)';
1846 $sql .=
' WHERE d.fk_propal = '.((int) $this->
id);
1847 if ($only_product) {
1848 $sql .=
' AND p.fk_product_type = 0';
1850 if ($sqlforgedfilters) {
1851 $sql .= $sqlforgedfilters;
1853 $sql .=
' ORDER by d.rang';
1855 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1856 $result = $this->db->query($sql);
1858 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
1860 $num = $this->db->num_rows($result);
1864 $objp = $this->db->fetch_object($result);
1868 $line->rowid = $objp->rowid;
1869 $line->id = $objp->rowid;
1870 $line->fk_propal = $objp->fk_propal;
1871 $line->fk_parent_line = $objp->fk_parent_line;
1872 $line->product_type = $objp->product_type;
1873 $line->label = $objp->custom_label;
1874 $line->desc = $objp->description;
1875 $line->description = $objp->description;
1876 $line->qty = $objp->qty;
1877 $line->vat_src_code = $objp->vat_src_code;
1878 $line->tva_tx = $objp->tva_tx;
1879 $line->localtax1_tx = $objp->localtax1_tx;
1880 $line->localtax2_tx = $objp->localtax2_tx;
1881 $line->localtax1_type = $objp->localtax1_type;
1882 $line->localtax2_type = $objp->localtax2_type;
1883 $line->subprice = $objp->subprice;
1884 $line->fk_remise_except = $objp->fk_remise_except;
1885 $line->remise_percent = $objp->remise_percent;
1886 $line->price = $objp->price;
1888 $line->info_bits = $objp->info_bits;
1889 $line->total_ht = $objp->total_ht;
1890 $line->total_tva = $objp->total_tva;
1891 $line->total_localtax1 = $objp->total_localtax1;
1892 $line->total_localtax2 = $objp->total_localtax2;
1893 $line->total_ttc = $objp->total_ttc;
1894 $line->fk_fournprice = $objp->fk_fournprice;
1895 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1896 $line->pa_ht = $marginInfos[0];
1897 $line->marge_tx = $marginInfos[1];
1898 $line->marque_tx = $marginInfos[2];
1899 $line->special_code = $objp->special_code;
1900 $line->rang = $objp->rang;
1902 $line->fk_product = $objp->fk_product;
1904 $line->ref = $objp->product_ref;
1905 $line->libelle = $objp->product_label;
1907 $line->product_ref = $objp->product_ref;
1908 $line->product_label = $objp->product_label;
1909 $line->product_desc = $objp->product_desc;
1910 $line->product_tobatch = $objp->product_tobatch;
1911 $line->product_barcode = $objp->product_barcode;
1913 $line->fk_product_type = $objp->fk_product_type;
1914 $line->fk_unit = $objp->fk_unit;
1915 $line->weight = $objp->weight;
1916 $line->weight_units = $objp->weight_units;
1917 $line->volume = $objp->volume;
1918 $line->volume_units = $objp->volume_units;
1920 $line->date_start = $this->db->jdate($objp->date_start);
1921 $line->date_end = $this->db->jdate($objp->date_end);
1924 $line->fk_multicurrency = $objp->fk_multicurrency;
1925 $line->multicurrency_code = $objp->multicurrency_code;
1926 $line->multicurrency_subprice = $objp->multicurrency_subprice;
1927 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
1928 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
1929 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
1931 $line->fetch_optionals();
1934 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
1935 $tmpproduct =
new Product($this->db);
1936 $tmpproduct->fetch($objp->fk_product);
1937 $tmpproduct->getMultiLangs();
1939 $line->multilangs = $tmpproduct->multilangs;
1942 $this->lines[$i] = $line;
1947 $this->db->free($result);
1951 $this->error = $this->db->lasterror();
1963 public function valid($user, $notrigger = 0)
1967 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1972 if ($this->
statut == self::STATUS_VALIDATED) {
1973 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
1977 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'creer'))
1978 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'propal_advance',
'validate')))) {
1979 $this->error =
'ErrorPermissionDenied';
1980 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
1989 $soc =
new Societe($this->db);
1990 $soc->fetch($this->socid);
1993 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
2000 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2001 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
2002 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
", date_valid='".$this->db->idate($now).
"', fk_user_valid=".((int) $user->id);
2005 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
2006 $resql = $this->db->query($sql);
2013 if (!$error && !$notrigger) {
2015 $result = $this->
call_trigger(
'PROPAL_VALIDATE', $user);
2023 $this->oldref = $this->ref;
2026 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
2028 $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).
"'";
2029 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
2030 $resql = $this->db->query($sql);
2033 $this->error = $this->db->lasterror();
2035 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'propale/".$this->db->escape($this->newref).
"'";
2036 $sql .=
" WHERE filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
2037 $resql = $this->db->query($sql);
2040 $this->error = $this->db->lasterror();
2046 $dirsource = $conf->propal->multidir_output[$this->entity].
'/'.$oldref;
2047 $dirdest = $conf->propal->multidir_output[$this->entity].
'/'.$newref;
2048 if (!$error && file_exists($dirsource)) {
2049 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
2050 if (@rename($dirsource, $dirdest)) {
2053 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
2054 foreach ($listoffiles as $fileentry) {
2055 $dirsource = $fileentry[
'name'];
2056 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
2057 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
2058 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
2059 @rename($dirsource, $dirdest);
2068 $this->user_validation_id = $user->id;
2069 $this->datev = $now;
2070 $this->date_validation = $now;
2072 $this->db->commit();
2075 $this->db->rollback();
2094 $this->error =
'ErrorBadParameter';
2095 dol_syslog(get_class($this).
"::set_date ".$this->error, LOG_ERR);
2099 if ($user->hasRight(
'propal',
'creer')) {
2104 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET datep = '".$this->db->idate($date).
"'";
2105 $sql .=
" WHERE rowid = ".((int) $this->
id);
2108 $resql = $this->db->query($sql);
2110 $this->errors[] = $this->db->error();
2115 $this->oldcopy = clone $this;
2116 $this->date = $date;
2117 $this->datep = $date;
2120 if (!$notrigger && empty($error)) {
2130 $this->db->commit();
2133 foreach ($this->errors as $errmsg) {
2134 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2135 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2137 $this->db->rollback();
2157 if ($user->hasRight(
'propal',
'creer')) {
2162 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET fin_validite = ".($date_end_validity !=
'' ?
"'".$this->db->idate($date_end_validity).
"'" :
'null');
2163 $sql .=
" WHERE rowid = ".((int) $this->
id);
2167 $resql = $this->db->query($sql);
2169 $this->errors[] = $this->db->error();
2175 $this->oldcopy = clone $this;
2176 $this->fin_validite = $date_end_validity;
2179 if (!$notrigger && empty($error)) {
2189 $this->db->commit();
2192 foreach ($this->errors as $errmsg) {
2193 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2194 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2196 $this->db->rollback();
2230 if ($user->hasRight(
'propal',
'creer')) {
2235 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal ";
2236 $sql .=
" SET date_livraison = ".($delivery_date !=
'' ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2237 $sql .=
" WHERE rowid = ".((int) $this->
id);
2240 $resql = $this->db->query($sql);
2242 $this->errors[] = $this->db->error();
2247 $this->oldcopy = clone $this;
2248 $this->delivery_date = $delivery_date;
2251 if (!$notrigger && empty($error)) {
2261 $this->db->commit();
2264 foreach ($this->errors as $errmsg) {
2265 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2266 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2268 $this->db->rollback();
2288 if ($user->hasRight(
'propal',
'creer') && $this->statut >= self::STATUS_DRAFT) {
2293 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2294 $sql .=
" SET fk_availability = ".((int) $id);
2295 $sql .=
" WHERE rowid = ".((int) $this->
id);
2297 dol_syslog(__METHOD__.
' availability('.$id.
')', LOG_DEBUG);
2298 $resql = $this->db->query($sql);
2300 $this->errors[] = $this->db->error();
2305 $this->oldcopy = clone $this;
2306 $this->fk_availability = $id;
2307 $this->availability_id = $id;
2310 if (!$notrigger && empty($error)) {
2320 $this->db->commit();
2323 foreach ($this->errors as $errmsg) {
2324 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2325 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2327 $this->db->rollback();
2331 $error_str =
'Propal status do not meet requirement '.$this->statut;
2333 $this->error = $error_str;
2334 $this->errors[] = $this->error;
2351 if ($user->hasRight(
'propal',
'creer') && $this->statut >= self::STATUS_DRAFT) {
2356 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal ";
2357 $sql .=
" SET fk_input_reason = ".((int) $id);
2358 $sql .=
" WHERE rowid = ".((int) $this->
id);
2361 $resql = $this->db->query($sql);
2363 $this->errors[] = $this->db->error();
2369 $this->oldcopy = clone $this;
2371 $this->demand_reason_id = $id;
2375 if (!$notrigger && empty($error)) {
2385 $this->db->commit();
2388 foreach ($this->errors as $errmsg) {
2389 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2390 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2392 $this->db->rollback();
2396 $error_str =
'Propal status do not meet requirement '.$this->statut;
2398 $this->error = $error_str;
2399 $this->errors[] = $this->error;
2416 if ($user->hasRight(
'propal',
'creer')) {
2421 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
2422 $sql .=
" WHERE rowid = ".((int) $this->
id);
2424 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
2425 $resql = $this->db->query($sql);
2427 $this->errors[] = $this->db->error();
2432 $this->oldcopy = clone $this;
2433 $this->ref_client = $ref_client;
2436 if (!$notrigger && empty($error)) {
2446 $this->db->commit();
2449 foreach ($this->errors as $errmsg) {
2450 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2451 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2453 $this->db->rollback();
2471 public function reopen($user, $status, $note =
'', $notrigger = 0)
2475 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2476 $sql .=
" SET fk_statut = ".((int) $status).
",";
2477 if (!empty($note)) {
2478 $sql .=
" note_private = '".$this->db->escape($note).
"',";
2480 $sql .=
" date_cloture=NULL, fk_user_cloture=NULL";
2481 $sql .=
" WHERE rowid = ".((int) $this->
id);
2485 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
2486 $resql = $this->db->query($sql);
2489 $this->errors[] =
"Error ".$this->db->lasterror();
2504 if (!empty($this->errors)) {
2505 foreach ($this->errors as $errmsg) {
2506 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2507 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2510 $this->db->rollback();
2516 $this->db->commit();
2532 global $langs,$conf;
2542 $date_signature = $now;
2543 $fk_user_signature = $user->id;
2545 $this->
info($this->
id);
2546 if (!isset($this->date_signature) || $this->date_signature ==
'') {
2547 $date_signature = $now;
2548 $fk_user_signature = $user->id;
2550 $date_signature = $this->date_signature;
2551 $fk_user_signature = $this->user_signature->id;
2555 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2556 $sql .=
" SET fk_statut = ".((int) $status).
", note_private = '".$this->db->escape($newprivatenote).
"'";
2557 if ($status == self::STATUS_SIGNED) {
2558 $sql .=
", date_signature='".$this->db->idate($now).
"', fk_user_signature = ".($fk_user_signature);
2560 $sql .=
" WHERE rowid = ".((int) $this->
id);
2562 $resql = $this->db->query($sql);
2566 $trigger_name =
'PROPAL_CLOSE_REFUSED';
2568 if ($status == self::STATUS_SIGNED) {
2569 $trigger_name =
'PROPAL_CLOSE_SIGNED';
2570 $modelpdf =
getDolGlobalString(
'PROPALE_ADDON_PDF_ODT_TOBILL') ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->model_pdf;
2573 $soc =
new Societe($this->db);
2574 $soc->id = $this->socid;
2575 $result = $soc->setAsCustomer();
2578 $this->error = $this->db->lasterror();
2579 $this->db->rollback();
2586 $outputlangs = $langs;
2588 $outputlangs =
new Translate(
"", $conf);
2589 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2590 $outputlangs->setDefaultLang($newlang);
2599 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2603 $this->oldcopy = clone $this;
2606 $this->date_signature = $date_signature;
2607 $this->note_private = $newprivatenote;
2610 if (!$notrigger && empty($error)) {
2620 $this->db->commit();
2623 $this->
statut = $this->oldcopy->statut;
2624 $this->
status = $this->oldcopy->statut;
2625 $this->date_signature = $this->oldcopy->date_signature;
2626 $this->note_private = $this->oldcopy->note_private;
2628 $this->db->rollback();
2632 $this->error = $this->db->lasterror();
2633 $this->db->rollback();
2648 global $conf, $langs;
2655 $triggerName =
'PROPAL_CLASSIFY_BILLED';
2661 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal SET fk_statut = '.self::STATUS_BILLED.
", ";
2662 $sql .=
" note_private = '".$this->db->escape($newprivatenote).
"', date_cloture='".$this->db->idate($now).
"', fk_user_cloture=".((int) $user->id);
2663 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_SIGNED);
2666 $resql = $this->db->query($sql);
2668 $this->errors[] = $this->db->error();
2671 $num = $this->db->affected_rows($resql);
2679 $outputlangs = $langs;
2681 $outputlangs =
new Translate(
"", $conf);
2682 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2683 $outputlangs->setDefaultLang($newlang);
2692 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2695 $this->oldcopy = clone $this;
2697 $this->date_cloture = $now;
2698 $this->note_private = $newprivatenote;
2701 if (!$notrigger && empty($error)) {
2711 $this->db->commit();
2714 foreach ($this->errors as $errmsg) {
2715 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2716 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2718 $this->db->rollback();
2735 $sql =
"UPDATE ". MAIN_DB_PREFIX .
"propal";
2736 $sql .=
" SET fk_statut = " . self::STATUS_CANCELED .
",";
2737 $sql .=
" fk_user_modif = " . ((int) $user->id);
2738 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2740 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
2741 if ($this->db->query($sql)) {
2753 $this->db->commit();
2756 foreach ($this->errors as $errmsg) {
2757 dol_syslog(get_class($this).
"::cancel ".$errmsg, LOG_ERR);
2758 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2760 $this->db->rollback();
2764 $this->error = $this->db->error();
2765 $this->db->rollback();
2784 if ($this->
statut <= self::STATUS_DRAFT) {
2788 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
2792 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
2793 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2794 $sql .=
", online_sign_ip = NULL , online_sign_name = NULL";
2795 $sql .=
" WHERE rowid = ".((int) $this->
id);
2797 $resql = $this->db->query($sql);
2799 $this->errors[] = $this->db->error();
2804 $this->oldcopy = clone $this;
2807 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();
2847 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datep', $sortorder =
'DESC')
2854 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
2855 $sql .=
" p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
2856 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
2857 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"propal as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
2858 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
2859 $sql .=
" AND p.fk_soc = s.rowid";
2860 $sql .=
" AND p.fk_statut = c.id";
2864 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2865 $search_sale = $user->id;
2868 if ($search_sale && $search_sale !=
'-1') {
2869 if ($search_sale == -2) {
2870 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
2871 } elseif ($search_sale > 0) {
2872 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
2877 $sql .=
" AND p.fk_soc = ".((int) $socid);
2880 $sql .=
" AND p.fk_statut = ".((int) self::STATUS_DRAFT);
2882 if ($notcurrentuser > 0) {
2883 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
2885 $sql .= $this->db->order($sortfield, $sortorder);
2886 $sql .= $this->db->plimit($limit, $offset);
2888 $result = $this->db->query($sql);
2890 $num = $this->db->num_rows($result);
2894 $obj = $this->db->fetch_object($result);
2896 if ($shortlist == 1) {
2897 $ga[$obj->propalid] = $obj->ref;
2898 } elseif ($shortlist == 2) {
2899 $ga[$obj->propalid] = $obj->ref.
' ('.$obj->name.
')';
2901 $ga[$i][
'id'] = $obj->propalid;
2902 $ga[$i][
'ref'] = $obj->ref;
2903 $ga[$i][
'name'] = $obj->name;
2937 $linkedInvoices = array();
2940 foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
2943 foreach ($objectid as $key =>
$object) {
2945 if ($objecttype ==
'facture') {
2950 foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
2951 foreach ($subobjectid as $subkey => $subobject) {
2952 if ($subobjecttype ==
'facture') {
2953 $linkedInvoices[] = $subobject;
2961 if (count($linkedInvoices) > 0) {
2962 $sql =
"SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye";
2963 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
2964 $sql .=
" WHERE rowid IN (".$this->db->sanitize(implode(
',', $linkedInvoices)).
")";
2966 dol_syslog(get_class($this).
"::InvoiceArrayList", LOG_DEBUG);
2967 $resql = $this->db->query($sql);
2970 $tab_sqlobj = array();
2971 $nump = $this->db->num_rows($resql);
2972 for ($i = 0; $i < $nump; $i++) {
2973 $sqlobj = $this->db->fetch_object($resql);
2974 $tab_sqlobj[] = $sqlobj;
2976 $this->db->free($resql);
2978 $nump = count($tab_sqlobj);
2982 while ($i < $nump) {
2983 $obj = array_shift($tab_sqlobj);
3006 public function delete($user, $notrigger = 0)
3009 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3025 if (!$error && !empty($this->table_element_line)) {
3026 $tabletodelete = $this->table_element_line;
3027 $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).
")";
3028 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3029 if (!$this->db->query($sqlef) || !$this->db->query($sql)) {
3031 $this->error = $this->db->lasterror();
3032 $this->errors[] = $this->error;
3033 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3058 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3064 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3065 $res = $this->db->query($sql);
3068 $this->error = $this->db->lasterror();
3069 $this->errors[] = $this->error;
3070 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3086 if ($conf->propal->multidir_output[$this->entity] && !empty($this->
ref)) {
3087 $dir = $conf->propal->multidir_output[$this->entity].
"/".$ref;
3088 $file = $dir.
"/".$ref.
".pdf";
3089 if (file_exists($file)) {
3093 $this->error =
'ErrorFailToDeleteFile';
3094 $this->errors[] = $this->error;
3095 $this->db->rollback();
3099 if (file_exists($dir)) {
3102 $this->error =
'ErrorFailToDeleteDir';
3103 $this->errors[] = $this->error;
3104 $this->db->rollback();
3112 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3113 $this->db->commit();
3116 $this->db->rollback();
3133 if ($this->
statut >= self::STATUS_DRAFT) {
3138 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal';
3139 $sql .=
' SET fk_availability = '.((int) $availability_id);
3140 $sql .=
' WHERE rowid='.((int) $this->
id);
3142 dol_syslog(__METHOD__.
' availability('.$availability_id.
')', LOG_DEBUG);
3143 $resql = $this->db->query($sql);
3145 $this->errors[] = $this->db->error();
3150 $this->oldcopy = clone $this;
3151 $this->availability_id = $availability_id;
3154 if (!$notrigger && empty($error)) {
3164 $this->db->commit();
3167 foreach ($this->errors as $errmsg) {
3168 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3169 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3171 $this->db->rollback();
3175 $error_str =
'Propal status do not meet requirement '.$this->statut;
3177 $this->error = $error_str;
3178 $this->errors[] = $this->error;
3197 if ($this->
status >= self::STATUS_DRAFT) {
3202 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'propal';
3203 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
3204 $sql .=
' WHERE rowid='.((int) $this->
id);
3206 dol_syslog(__METHOD__.
' demand_reason('.$demand_reason_id.
')', LOG_DEBUG);
3207 $resql = $this->db->query($sql);
3209 $this->errors[] = $this->db->error();
3214 $this->oldcopy = clone $this;
3215 $this->demand_reason_id = $demand_reason_id;
3218 if (!$notrigger && empty($error)) {
3228 $this->db->commit();
3231 foreach ($this->errors as $errmsg) {
3232 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3233 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3235 $this->db->rollback();
3239 $error_str =
'Propal status do not meet requirement '.$this->statut;
3241 $this->error = $error_str;
3242 $this->errors[] = $this->error;
3256 $sql =
"SELECT c.rowid, ";
3257 $sql .=
" c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,";
3258 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
3259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as c";
3260 $sql .=
" WHERE c.rowid = ".((int) $id);
3262 $result = $this->db->query($sql);
3265 if ($this->db->num_rows($result)) {
3266 $obj = $this->db->fetch_object($result);
3268 $this->
id = $obj->rowid;
3270 $this->date_creation = $this->db->jdate($obj->datec);
3271 $this->date_validation = $this->db->jdate($obj->datev);
3272 $this->date_signature = $this->db->jdate($obj->date_signature);
3273 $this->date_cloture = $this->db->jdate($obj->date_cloture);
3275 $this->user_creation_id = $obj->fk_user_author;
3276 $this->user_validation_id = $obj->fk_user_valid;
3278 if ($obj->fk_user_signature) {
3279 $user_signature =
new User($this->db);
3280 $user_signature->fetch($obj->fk_user_signature);
3281 $this->user_signature = $user_signature;
3284 $this->user_closing_id = $obj->fk_user_cloture;
3286 $this->db->free($result);
3315 global $hookmanager;
3318 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3320 $langs->load(
"propal");
3321 $this->labelStatus[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceled");
3322 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraft");
3323 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidated");
3324 $this->labelStatus[2] = $langs->transnoentitiesnoconv(
"PropalStatusSigned");
3325 $this->labelStatus[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSigned");
3326 $this->labelStatus[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilled");
3327 $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceledShort");
3328 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraftShort");
3329 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidatedShort");
3330 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv(
"PropalStatusSignedShort");
3331 $this->labelStatusShort[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSignedShort");
3332 $this->labelStatusShort[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilledShort");
3336 if ($status == self::STATUS_CANCELED) {
3337 $statusType =
'status9';
3338 } elseif ($status == self::STATUS_DRAFT) {
3339 $statusType =
'status0';
3340 } elseif ($status == self::STATUS_VALIDATED) {
3341 $statusType =
'status1';
3342 } elseif ($status == self::STATUS_SIGNED) {
3343 $statusType =
'status4';
3344 } elseif ($status == self::STATUS_NOTSIGNED) {
3345 $statusType =
'status9';
3346 } elseif ($status == self::STATUS_BILLED) {
3347 $statusType =
'status6';
3350 $parameters = array(
'status' => $status,
'mode' => $mode);
3351 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3354 return $hookmanager->resPrint;
3357 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3372 global $conf, $langs;
3376 $sql =
"SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
3377 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3378 $sql .= $clause.
" p.entity IN (".
getEntity(
'propal').
")";
3379 if ($mode ==
'opened') {
3380 $sql .=
" AND p.fk_statut = ".self::STATUS_VALIDATED;
3382 if ($mode ==
'signed') {
3383 $sql .=
" AND p.fk_statut = ".self::STATUS_SIGNED;
3387 if (!$user->hasRight(
'societe',
'client',
'voir')) {
3388 $search_sale = $user->id;
3391 if ($search_sale && $search_sale !=
'-1') {
3392 if ($search_sale == -2) {
3393 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3394 } elseif ($search_sale > 0) {
3395 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
3399 $resql = $this->db->query($sql);
3401 $langs->load(
"propal");
3406 $label = $labelShort =
'';
3407 if ($mode ==
'opened') {
3408 $delay_warning = $conf->propal->cloture->warning_delay;
3410 $label = $langs->transnoentitiesnoconv(
"PropalsToClose");
3411 $labelShort = $langs->transnoentitiesnoconv(
"ToAcceptRefuse");
3413 if ($mode ==
'signed') {
3414 $delay_warning = $conf->propal->facturation->warning_delay;
3416 $label = $langs->trans(
"PropalsToBill");
3417 $labelShort = $langs->trans(
"ToBill");
3421 $response->warning_delay = $delay_warning / 60 / 60 / 24;
3422 $response->label = $label;
3423 $response->labelShort = $labelShort;
3424 $response->url = DOL_URL_ROOT.
'/comm/propal/list.php?search_status='.$status.
'&mainmenu=commercial&leftmenu=propals';
3425 $response->url_late = DOL_URL_ROOT.
'/comm/propal/list.php?search_option=late&mainmenu=commercial&leftmenu=propals&sortfield=p.datep&sortorder=asc';
3429 while ($obj = $this->db->fetch_object($resql)) {
3430 $response->nbtodo++;
3431 $response->total += $obj->total_ht;
3433 if ($mode ==
'opened') {
3434 $datelimit = $this->db->jdate($obj->datefin);
3435 if ($datelimit < ($now - $delay_warning)) {
3436 $response->nbtodolate++;
3445 $this->error = $this->db->error();
3460 global $conf, $langs;
3465 $sql =
"SELECT rowid";
3466 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3467 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3468 $sql .= $this->db->plimit(100);
3470 $resql = $this->db->query($sql);
3472 $num_prods = $this->db->num_rows($resql);
3474 while ($i < $num_prods) {
3476 $row = $this->db->fetch_row($resql);
3477 $prodids[$i] = $row[0];
3483 $this->
ref =
'SPECIMEN';
3484 $this->ref_client =
'NEMICEPS';
3485 $this->specimen = 1;
3487 $this->date = time();
3488 $this->fin_validite = $this->date + 3600 * 24 * 30;
3489 $this->cond_reglement_id = 1;
3490 $this->cond_reglement_code =
'RECEP';
3491 $this->mode_reglement_id = 7;
3492 $this->mode_reglement_code =
'CHQ';
3493 $this->availability_id = 1;
3494 $this->availability_code =
'AV_NOW';
3495 $this->demand_reason_id = 1;
3496 $this->demand_reason_code =
'SRC_00';
3497 $this->note_public =
'This is a comment (public)';
3498 $this->note_private =
'This is a comment (private)';
3500 $this->multicurrency_tx = 1;
3501 $this->multicurrency_code = $conf->currency;
3506 while ($xnbp < $nbp) {
3508 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3510 $line->subprice = 100;
3513 $line->localtax1_tx = 0;
3514 $line->localtax2_tx = 0;
3516 $line->total_ht = 50;
3517 $line->total_ttc = 60;
3518 $line->total_tva = 10;
3519 $line->remise_percent = 50;
3521 $line->total_ht = 100;
3522 $line->total_ttc = 120;
3523 $line->total_tva = 20;
3524 $line->remise_percent = 00;
3527 if ($num_prods > 0) {
3528 $prodid = mt_rand(1, $num_prods);
3529 $line->fk_product = $prodids[$prodid];
3530 $line->product_ref =
'SPECIMEN';
3533 $this->lines[$xnbp] = $line;
3535 $this->total_ht += $line->total_ht;
3536 $this->total_tva += $line->total_tva;
3537 $this->total_ttc += $line->total_ttc;
3554 $this->nb = array();
3557 $sql =
"SELECT count(p.rowid) as nb";
3558 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3559 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3560 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'propal').
")";
3564 if (!$user->hasRight(
'societe',
'client',
'voir')) {
3565 $search_sale = $user->id;
3568 if ($search_sale && $search_sale !=
'-1') {
3569 if ($search_sale == -2) {
3570 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3571 } elseif ($search_sale > 0) {
3572 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
3576 $resql = $this->db->query($sql);
3579 while ($obj = $this->db->fetch_object($resql)) {
3580 $this->nb[
"proposals"] = $obj->nb;
3582 $this->db->free($resql);
3586 $this->error = $this->db->error();
3601 global $conf, $langs;
3602 $langs->load(
"propal");
3606 if (!empty($classname)) {
3609 $file = $classname.
".php";
3612 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
3613 foreach ($dirmodels as $reldir) {
3617 $mybool = ((bool) @include_once $dir.$file) || $mybool;
3625 $obj =
new $classname();
3627 $numref = $obj->getNextValue($soc, $this);
3629 if ($numref !=
"") {
3632 $this->error = $obj->error;
3637 $langs->load(
"errors");
3638 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Proposal"));
3651 global $conf, $langs, $user;
3653 $langs->load(
'propal');
3655 $nofetch = !empty($params[
'nofetch']);
3658 return [
'optimize' => $langs->trans(
"Proposal")];
3660 if ($user->hasRight(
'propal',
'lire')) {
3661 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Proposal").
'</u>';
3662 if (isset($this->
status)) {
3663 $datas[
'status'] =
' '.$this->getLibStatut(5);
3665 if (!empty($this->
ref)) {
3666 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3669 $langs->load(
'companies');
3670 if (empty($this->thirdparty)) {
3673 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
3675 if (!empty($this->ref_customer)) {
3676 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$this->ref_customer;
3679 $langs->load(
'project');
3680 if (is_null($this->project) || (is_object($this->project) && $this->project->isEmpty())) {
3682 if ($res > 0 && $this->project instanceof
Project) {
3683 $datas[
'project'] =
'<br><b>'.$langs->trans(
'Project').
':</b> '.$this->project->getNomUrl(1,
'', 0, 1);
3687 if (!empty($this->total_ht)) {
3688 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
3690 if (!empty($this->total_tva)) {
3691 $datas[
'vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
3693 if (!empty($this->total_ttc)) {
3694 $datas[
'amountttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
3696 if (!empty($this->date)) {
3697 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
3699 if (!empty($this->delivery_date)) {
3700 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3718 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1)
3720 global $langs, $conf, $user, $hookmanager;
3722 if (!empty($conf->dol_no_mouse_hover)) {
3729 'objecttype' => $this->element,
3730 'option' => $option,
3733 $classfortooltip =
'classfortooltip';
3736 $classfortooltip =
'classforajaxtooltip';
3737 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3744 if ($user->hasRight(
'propal',
'lire')) {
3745 if ($option ==
'') {
3746 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3747 } elseif ($option ==
'compta') {
3748 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3749 } elseif ($option ==
'expedition') {
3750 $url = DOL_URL_ROOT.
'/expedition/propal.php?id='.$this->
id.$get_params;
3751 } elseif ($option ==
'document') {
3752 $url = DOL_URL_ROOT.
'/comm/propal/document.php?id='.$this->
id.$get_params;
3755 if ($option !=
'nolink') {
3757 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3758 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3759 $add_save_lastsearch_values = 1;
3761 if ($add_save_lastsearch_values) {
3762 $url .=
'&save_lastsearch_values=1';
3768 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
3770 $label = $langs->trans(
"Proposal");
3771 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3773 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3774 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
3777 $linkstart =
'<a href="'.$url.
'"';
3778 $linkstart .= $linkclose.
'>';
3781 $result .= $linkstart;
3783 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
3785 if ($withpicto != 2) {
3786 $result .= $this->ref;
3788 $result .= $linkend;
3790 if ($addlinktonotes >= 0) {
3793 if ($addlinktonotes == 0) {
3794 if (!empty($this->note_private) || !empty($this->note_public)) {
3795 $txttoshow = $langs->trans(
'ViewPrivateNote');
3797 } elseif ($addlinktonotes == 1) {
3798 if (!empty($this->note_private)) {
3801 } elseif ($addlinktonotes == 2) {
3802 if (!empty($this->note_public)) {
3805 } elseif ($addlinktonotes == 3) {
3806 if ($user->socid > 0) {
3807 if (!empty($this->note_public)) {
3811 if (!empty($this->note_public)) {
3814 if (!empty($this->note_private)) {
3815 if (!empty($txttoshow)) {
3816 $txttoshow .=
'<br><br>';
3824 $result .=
' <span class="note inline-block">';
3825 $result .=
'<a href="'.DOL_URL_ROOT.
'/comm/propal/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($txttoshow).
'">';
3828 $result .=
'</span>';
3833 $hookmanager->initHooks(array($this->element .
'dao'));
3834 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3835 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3837 $result = $hookmanager->resPrint;
3839 $result .= $hookmanager->resPrint;
3852 return $this->
fetch_lines(0, 0, $sqlforgedfilters);
3866 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3868 global $conf, $langs;
3870 $langs->load(
"propale");
3871 $outputlangs->load(
"products");
3876 if ($this->model_pdf) {
3877 $modele = $this->model_pdf;
3883 $modelpath =
"core/modules/propale/doc/";
3885 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3933 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3935 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3936 $return .=
'<div class="info-box info-box-sm">';
3937 $return .=
'<div class="info-box-icon bg-infobox-action">';
3939 $return .=
'</div>';
3940 $return .=
'<div class="info-box-content">';
3941 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3942 if ($selected >= 0) {
3943 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3945 if (!empty($arraydata[
'projectlink'])) {
3946 $return .=
'<span class="info-box-ref"> | '.$arraydata[
'projectlink'].
'</span>';
3949 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
3950 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
3952 if (property_exists($this,
'total_ht')) {
3953 $return .=
'<span class="info-box-label amount" title="'.$langs->trans(
"AmountHT").
'">'.
price($this->total_ht).
'</span>';
3955 if (!empty($arraydata[
'authorlink'])) {
3956 $return .=
' <span class="info-box-label">'.$arraydata[
'authorlink'].
'</span>';
3958 if (method_exists($this,
'getLibStatut')) {
3959 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3961 $return .=
'</div>';
3962 $return .=
'</div>';
3963 $return .=
'</div>';
3976 public $element =
'propaldet';
3981 public $table_element =
'propaldet';
3997 public $fk_parent_line;
4015 public $vat_src_code;
4022 public $remise_percent;
4023 public $fk_remise_except;
4027 public $fk_fournprice;
4038 public $special_code;
4040 public $info_bits = 0;
4069 public $product_ref;
4084 public $product_label;
4089 public $product_desc;
4095 public $product_tobatch;
4101 public $product_barcode;
4103 public $localtax1_tx;
4104 public $localtax2_tx;
4105 public $localtax1_type;
4106 public $localtax2_type;
4107 public $total_localtax1;
4108 public $total_localtax2;
4113 public $skip_update_total;
4116 public $fk_multicurrency;
4117 public $multicurrency_code;
4118 public $multicurrency_subprice;
4119 public $multicurrency_total_ht;
4120 public $multicurrency_total_tva;
4121 public $multicurrency_total_ttc;
4142 $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,';
4143 $sql .=
' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
4144 $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,';
4145 $sql .=
' pd.fk_unit,';
4146 $sql .=
' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
4147 $sql .=
' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
4148 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
4149 $sql .=
' pd.date_start, pd.date_end, pd.product_type';
4150 $sql .=
' FROM '.MAIN_DB_PREFIX.
'propaldet as pd';
4151 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON pd.fk_product = p.rowid';
4152 $sql .=
' WHERE pd.rowid = '.((int) $rowid);
4154 $result = $this->db->query($sql);
4156 $objp = $this->db->fetch_object($result);
4159 $this->
id = $objp->rowid;
4160 $this->
rowid = $objp->rowid;
4161 $this->fk_propal = $objp->fk_propal;
4162 $this->fk_parent_line = $objp->fk_parent_line;
4163 $this->label = $objp->custom_label;
4164 $this->desc = $objp->description;
4165 $this->qty = $objp->qty;
4166 $this->
price = $objp->price;
4167 $this->subprice = $objp->subprice;
4168 $this->vat_src_code = $objp->vat_src_code;
4169 $this->tva_tx = $objp->tva_tx;
4170 $this->remise = $objp->remise;
4171 $this->remise_percent = $objp->remise_percent;
4172 $this->fk_remise_except = $objp->fk_remise_except;
4173 $this->fk_product = $objp->fk_product;
4174 $this->info_bits = $objp->info_bits;
4176 $this->total_ht = $objp->total_ht;
4177 $this->total_tva = $objp->total_tva;
4178 $this->total_ttc = $objp->total_ttc;
4180 $this->fk_fournprice = $objp->fk_fournprice;
4182 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
4183 $this->pa_ht = $marginInfos[0];
4184 $this->marge_tx = $marginInfos[1];
4185 $this->marque_tx = $marginInfos[2];
4187 $this->special_code = $objp->special_code;
4188 $this->product_type = $objp->product_type;
4189 $this->rang = $objp->rang;
4191 $this->
ref = $objp->product_ref;
4192 $this->product_ref = $objp->product_ref;
4193 $this->libelle = $objp->product_label;
4194 $this->product_label = $objp->product_label;
4195 $this->product_desc = $objp->product_desc;
4196 $this->fk_unit = $objp->fk_unit;
4198 $this->date_start = $this->db->jdate($objp->date_start);
4199 $this->date_end = $this->db->jdate($objp->date_end);
4202 $this->fk_multicurrency = $objp->fk_multicurrency;
4203 $this->multicurrency_code = $objp->multicurrency_code;
4204 $this->multicurrency_subprice = $objp->multicurrency_subprice;
4205 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
4206 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
4207 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
4211 $this->db->free($result);
4230 global $conf, $user;
4234 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
4236 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht ==
'');
4239 if (empty($this->tva_tx)) {
4242 if (empty($this->localtax1_tx)) {
4243 $this->localtax1_tx = 0;
4245 if (empty($this->localtax2_tx)) {
4246 $this->localtax2_tx = 0;
4248 if (empty($this->localtax1_type)) {
4249 $this->localtax1_type = 0;
4251 if (empty($this->localtax2_type)) {
4252 $this->localtax2_type = 0;
4254 if (empty($this->total_localtax1)) {
4255 $this->total_localtax1 = 0;
4257 if (empty($this->total_localtax2)) {
4258 $this->total_localtax2 = 0;
4260 if (empty($this->rang)) {
4263 if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
4264 $this->remise_percent = 0;
4266 if (empty($this->info_bits)) {
4267 $this->info_bits = 0;
4269 if (empty($this->special_code)) {
4270 $this->special_code = 0;
4272 if (empty($this->fk_parent_line)) {
4273 $this->fk_parent_line = 0;
4275 if (empty($this->fk_fournprice)) {
4276 $this->fk_fournprice = 0;
4278 if (!is_numeric($this->qty)) {
4281 if (empty($this->pa_ht)) {
4284 if (empty($this->multicurrency_subprice)) {
4285 $this->multicurrency_subprice = 0;
4287 if (empty($this->multicurrency_total_ht)) {
4288 $this->multicurrency_total_ht = 0;
4290 if (empty($this->multicurrency_total_tva)) {
4291 $this->multicurrency_total_tva = 0;
4293 if (empty($this->multicurrency_total_ttc)) {
4294 $this->multicurrency_total_ttc = 0;
4298 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
4299 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
4302 $this->pa_ht = $result;
4307 if ($this->product_type < 0) {
4314 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'propaldet';
4315 $sql .=
' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
4316 $sql .=
' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
4317 $sql .=
' subprice, remise_percent, ';
4318 $sql .=
' info_bits, ';
4319 $sql .=
' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
4320 $sql .=
' fk_unit,';
4321 $sql .=
' date_start, date_end';
4322 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
4323 $sql .=
" VALUES (".$this->fk_propal.
",";
4324 $sql .=
" ".($this->fk_parent_line > 0 ?
"'".$this->db->escape($this->fk_parent_line).
"'" :
"null").
",";
4325 $sql .=
" ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
4326 $sql .=
" '".$this->db->escape($this->desc).
"',";
4327 $sql .=
" ".($this->fk_product ?
"'".$this->db->escape($this->fk_product).
"'" :
"null").
",";
4328 $sql .=
" '".$this->db->escape($this->product_type).
"',";
4329 $sql .=
" ".($this->fk_remise_except ?
"'".$this->db->escape($this->fk_remise_except).
"'" :
"null").
",";
4330 $sql .=
" ".price2num($this->qty,
'MS').
",";
4331 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4332 $sql .=
" ".price2num($this->tva_tx).
",";
4333 $sql .=
" ".price2num($this->localtax1_tx).
",";
4334 $sql .=
" ".price2num($this->localtax2_tx).
",";
4335 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4336 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4337 $sql .=
" ".(price2num($this->subprice) !==
'' ?
price2num($this->subprice,
'MU') :
"null").
",";
4338 $sql .=
" ".price2num($this->remise_percent, 3).
",";
4339 $sql .=
" ".(isset($this->info_bits) ? ((int) $this->info_bits) :
"null").
",";
4340 $sql .=
" ".price2num($this->total_ht,
'MT').
",";
4341 $sql .=
" ".price2num($this->total_tva,
'MT').
",";
4342 $sql .=
" ".price2num($this->total_localtax1,
'MT').
",";
4343 $sql .=
" ".price2num($this->total_localtax2,
'MT').
",";
4344 $sql .=
" ".price2num($this->total_ttc,
'MT').
",";
4345 $sql .=
" ".(!empty($this->fk_fournprice) ?
"'".$this->db->escape($this->fk_fournprice).
"'" :
"null").
",";
4346 $sql .=
" ".(isset($this->pa_ht) ?
"'".price2num($this->pa_ht).
"'" :
"null").
",";
4347 $sql .=
' '.((int) $this->special_code).
',';
4348 $sql .=
' '.((int) $this->rang).
',';
4349 $sql .=
' '.(empty($this->fk_unit) ?
'NULL' : ((int) $this->fk_unit)).
',';
4350 $sql .=
" ".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
',';
4351 $sql .=
" ".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4352 $sql .=
", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) :
'null');
4353 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4354 $sql .=
", ".price2num($this->multicurrency_subprice,
'CU');
4355 $sql .=
", ".price2num($this->multicurrency_total_ht,
'CT');
4356 $sql .=
", ".price2num($this->multicurrency_total_tva,
'CT');
4357 $sql .=
", ".price2num($this->multicurrency_total_ttc,
'CT');
4360 dol_syslog(get_class($this).
'::insert', LOG_DEBUG);
4361 $resql = $this->db->query($sql);
4363 $this->
rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
'propaldet');
4366 $this->
id = $this->rowid;
4373 if (!$error && !$notrigger) {
4375 $result = $this->
call_trigger(
'LINEPROPAL_INSERT', $user);
4377 $this->db->rollback();
4383 $this->db->commit();
4386 $this->error = $this->db->error().
" sql=".$sql;
4387 $this->db->rollback();
4399 public function delete(
User $user, $notrigger = 0)
4408 $result = $this->
call_trigger(
'LINEPROPAL_DELETE', $user);
4416 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"propaldet WHERE rowid = " . ((int) $this->
rowid);
4417 dol_syslog(
"PropaleLigne::delete", LOG_DEBUG);
4418 if ($this->db->query($sql)) {
4421 $this->
id = $this->rowid;
4425 dol_syslog(get_class($this) .
"::delete error -4 " . $this->error, LOG_ERR);
4429 $this->error = $this->db->error() .
" sql=" . $sql;
4435 $this->db->rollback();
4438 $this->db->commit();
4451 global $conf, $user;
4455 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht ==
'');
4457 if (empty($this->
id) && !empty($this->
rowid)) {
4458 $this->
id = $this->rowid;
4462 if (empty($this->tva_tx)) {
4465 if (empty($this->localtax1_tx)) {
4466 $this->localtax1_tx = 0;
4468 if (empty($this->localtax2_tx)) {
4469 $this->localtax2_tx = 0;
4471 if (empty($this->total_localtax1)) {
4472 $this->total_localtax1 = 0;
4474 if (empty($this->total_localtax2)) {
4475 $this->total_localtax2 = 0;
4477 if (empty($this->localtax1_type)) {
4478 $this->localtax1_type = 0;
4480 if (empty($this->localtax2_type)) {
4481 $this->localtax2_type = 0;
4483 if (empty($this->marque_tx)) {
4484 $this->marque_tx = 0;
4486 if (empty($this->marge_tx)) {
4487 $this->marge_tx = 0;
4489 if (empty($this->
price)) {
4492 if (empty($this->remise_percent)) {
4493 $this->remise_percent = 0;
4495 if (empty($this->info_bits)) {
4496 $this->info_bits = 0;
4498 if (empty($this->special_code)) {
4499 $this->special_code = 0;
4501 if (empty($this->fk_parent_line)) {
4502 $this->fk_parent_line = 0;
4504 if (empty($this->fk_fournprice)) {
4505 $this->fk_fournprice = 0;
4507 if (empty($this->subprice)) {
4508 $this->subprice = 0;
4510 if (empty($this->pa_ht)) {
4515 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
4516 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
4519 $this->pa_ht = $result;
4526 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propaldet SET";
4527 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4528 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
4529 $sql .=
", product_type=".$this->product_type;
4530 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4531 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4532 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
4533 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
4534 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4535 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4536 $sql .=
", qty='".price2num($this->qty).
"'";
4537 $sql .=
", subprice=".price2num($this->subprice);
4538 $sql .=
", remise_percent=".price2num($this->remise_percent);
4540 $sql .=
", remise=".(float)
price2num($this->remise);
4541 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4542 if (empty($this->skip_update_total)) {
4543 $sql .=
", total_ht=".price2num($this->total_ht);
4544 $sql .=
", total_tva=".price2num($this->total_tva);
4545 $sql .=
", total_ttc=".price2num($this->total_ttc);
4546 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
4547 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
4549 $sql .=
", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ?
"'".$this->db->escape($this->fk_fournprice).
"'" :
"null");
4550 $sql .=
", buy_price_ht=".price2num($this->pa_ht);
4551 $sql .=
", special_code=".((int) $this->special_code);
4552 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? (int) $this->fk_parent_line :
"null");
4553 if (!empty($this->rang)) {
4554 $sql .=
", rang=".((int) $this->rang);
4556 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4557 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4558 $sql .=
", fk_unit=".(!$this->fk_unit ?
'NULL' : $this->fk_unit);
4561 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4562 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4563 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4564 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4566 $sql .=
" WHERE rowid = ".((int) $this->
id);
4568 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
4569 $resql = $this->db->query($sql);
4578 if (!$error && !$notrigger) {
4580 $result = $this->
call_trigger(
'LINEPROPAL_MODIFY', $user);
4582 $this->db->rollback();
4588 $this->db->commit();
4591 $this->error = $this->db->error();
4592 $this->db->rollback();
4610 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propaldet SET";
4611 $sql .=
" total_ht=".price2num($this->total_ht,
'MT');
4612 $sql .=
",total_tva=".price2num($this->total_tva,
'MT');
4613 $sql .=
",total_ttc=".price2num($this->total_ttc,
'MT');
4614 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
4616 dol_syslog(
"PropaleLigne::update_total", LOG_DEBUG);
4618 $resql = $this->db->query($sql);
4620 $this->db->commit();
4623 $this->error = $this->db->error();
4624 $this->db->rollback();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
defineBuyPrice($unitPrice=0.0, $discountPercent=0.0, $fk_product=0)
Get buy price to use for margin calculation.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
updateRangOfLine($rowid, $rang)
Update position of line (rang)
fetch_project()
Load the project with id $this->fk_project into this->project.
deleteExtraFields()
Delete all extra fields values for the current object.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage absolute discounts.
Class to manage Dolibarr database access.
static getIdFromCode($dbs, $code)
Get id of currency from code.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
Class to manage projects.
Class to manage proposals.
getTooltipContentArray($params)
getTooltipContentArray
const STATUS_DRAFT
Draft status.
set_date($user, $date, $notrigger=0)
Define proposal date.
const STATUS_SIGNED
Signed quote.
getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=-1)
Return clicable link of object (with eventually picto)
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
InvoiceArrayList($id)
Returns an array with id and ref of related invoices.
availability($availability_id, $notrigger=0)
Change the delivery time.
const STATUS_NOTSIGNED
Not signed quote.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set delivery date.
classifyBilled(User $user, $notrigger=0, $note='')
Classify the proposal to status Billed.
getLinesArray($sqlforgedfilters='')
Retrieve an array of proposal lines.
fetch($rowid, $ref='', $ref_ext='', $forceentity=0)
Load a proposal from database.
set_availability($user, $id, $notrigger=0)
Set delivery.
fetch_lines($only_product=0, $loadalsotranslation=0, $sqlforgedfilters='')
Load array lines.
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=array(), $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $rang=0)
Update a proposal line.
update(User $user, $notrigger=0)
Update database.
demand_reason($demand_reason_id, $notrigger=0)
Change source demand.
info($id)
Object Proposal Information.
const STATUS_BILLED
Billed or processed quote.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLibStatut($mode=0)
Return label of status of proposal (draft, validated, ...)
const STATUS_CANCELED
Canceled status.
insert_discount($idremise)
Adding line of fixed discount in the proposal in DB.
getNextNumRef($soc)
Returns the reference to the following non used Proposal used depending on the active numbering modul...
LibStatut($status, $mode=1)
Return label of a status (draft, validated, ...)
valid($user, $notrigger=0)
Set status to validated.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
set_ref_client($user, $ref_client, $notrigger=0)
Set customer reference number.
setDraft($user, $notrigger=0)
Set draft status.
set_echeance($user, $date_end_validity, $notrigger=0)
Define end validity date.
set_demand_reason($user, $id, $notrigger=0)
Set source of demand.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
create($user, $notrigger=0)
Create commercial proposal into database this->ref can be set or empty.
liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datep', $sortorder='DESC')
Return list of proposal (eventually filtered on user) into an array.
add_product($idproduct, $qty, $remise_percent=0)
Add line into array ->lines $this->thirdparty should be loaded.
initAsSpecimen()
Initialise an instance with random values.
closeProposal($user, $status, $note='', $notrigger=0)
Close/set the commercial proposal to status signed or refused (fill also date signature)
reopen($user, $status, $note='', $notrigger=0)
Reopen the commercial proposal.
deleteLine($lineid, $id=0)
Delete detail line.
__construct($db, $socid=0, $propalid=0)
Constructor.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
setCancel(User $user)
Cancel the proposal.
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=array(), $fk_unit=null, $origin='', $origin_id=0, $pu_ht_devise=0, $fk_remise_except=0, $noupdateafterinsertline=0)
Add a proposal line into database (linked to product/service or not) The parameters are already suppo...
getInvoiceArrayList()
Returns an array with the numbers of related invoices.
set_date_livraison($user, $delivery_date, $notrigger=0)
Set delivery date.
const STATUS_VALIDATED
Validated status.
loadStateBoard()
Load the indicators this->nb for the state board.
createFromClone(User $user, $socid=0, $forceentity=null, $update_prices=false, $update_desc=false)
Load an object from its id and create a new one in database.
Class to manage commercial proposal lines.
__construct($db)
Class line Constructor.
update($notrigger=0)
Update propal line object into DB.
fetch($rowid)
Retrieve the propal line object.
insert($notrigger=0)
Insert object line propal in database.
update_total()
Update DB line fields total_xxx Used by migration.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
trait CommonIncoterm
Superclass for incoterm classes.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid