44require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propaleligne.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/product/class/product.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';
50require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
57 use CommonIncoterm, CommonSubtotal;
67 public $element =
'propal';
72 public $table_element =
'propal';
77 public $table_element_line =
'propaldet';
82 public $fk_element =
'fk_propal';
87 public $picto =
'propal';
93 public $restrictiononfksoc = 1;
124 public $ref_customer;
158 public $date_validation;
163 public $date_signature;
168 public $user_signature;
185 public $delivery_date;
191 public $fin_validite;
196 public $user_author_id;
227 public $cond_reglement_code;
232 public $cond_reglement;
237 public $cond_reglement_doc;
242 public $cond_reglement_label;
247 public $mode_reglement_code;
252 public $mode_reglement;
259 public $deposit_percent;
271 public $address_type;
282 public $availability_id;
289 public $fk_availability;
294 public $availability_code;
299 public $availability;
304 public $duree_validite;
309 public $demand_reason_id;
314 public $demand_reason_code;
319 public $demand_reason;
324 public $warehouse_id;
329 public $lines = array();
336 public $labelStatus = array();
337 public $labelStatusShort = array();
368 public $fields = array(
369 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
370 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
371 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 20),
372 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 22),
373 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 40),
374 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'position' => 23),
375 '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),
376 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
377 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
378 'datep' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => -1,
'position' => 60),
379 'fin_validite' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' => 1,
'visible' => -1,
'position' => 65),
380 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 70),
381 'date_cloture' => array(
'type' =>
'datetime',
'label' =>
'DateClosing',
'enabled' => 1,
'visible' => -1,
'position' => 75),
382 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 80),
383 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 85),
384 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 90),
385 'fk_user_cloture' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user cloture',
'enabled' => 1,
'visible' => -1,
'position' => 95),
386 'price' => array(
'type' =>
'double',
'label' =>
'Price',
'enabled' => 1,
'visible' => -1,
'position' => 105),
387 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 125,
'isameasure' => 1),
388 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'VAT',
'enabled' => 1,
'visible' => -1,
'position' => 130,
'isameasure' => 1),
389 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax1',
'enabled' => 1,
'visible' => -1,
'position' => 135,
'isameasure' => 1),
390 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax2',
'enabled' => 1,
'visible' => -1,
'position' => 140,
'isameasure' => 1),
391 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 145,
'isameasure' => 1),
392 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 150),
393 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 155),
394 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 160),
395 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 161),
396 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 165),
397 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 170),
398 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 175),
399 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 180),
400 'date_livraison' => array(
'type' =>
'date',
'label' =>
'DateDeliveryPlanned',
'enabled' => 1,
'visible' => -1,
'position' => 185),
401 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMethod',
'enabled' => 1,
'visible' => -1,
'position' => 190),
402 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Fk warehouse',
'enabled' =>
'isModEnabled("stock")',
'visible' => -1,
'position' => 191),
403 'fk_availability' => array(
'type' =>
'integer',
'label' =>
'Availability',
'enabled' => 1,
'visible' => -1,
'position' => 195),
404 'fk_delivery_address' => array(
'type' =>
'integer',
'label' =>
'DeliveryAddress',
'enabled' => 1,
'visible' => 0,
'position' => 200),
405 'fk_input_reason' => array(
'type' =>
'integer',
'label' =>
'InputReason',
'enabled' => 1,
'visible' => -1,
'position' => 205),
406 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 215),
407 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 220),
408 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLabel',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 225),
409 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'MulticurrencyID',
'enabled' => 1,
'visible' => -1,
'position' => 230),
410 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCurrency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
411 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240,
'isameasure' => 1),
412 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 245,
'isameasure' => 1),
413 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 250,
'isameasure' => 1),
414 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 255,
'isameasure' => 1),
415 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 260),
416 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
417 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
458 $this->ismultientitymanaged = 1;
459 $this->socid = $socid;
460 $this->
id = $propalid;
464 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
480 public function add_product($idproduct, $qty, $remise_percent = 0)
483 global
$conf, $mysoc;
489 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
490 if ($idproduct > 0) {
491 $prod =
new Product($this->db);
492 $prod->fetch($idproduct);
494 $productdesc = $prod->description;
496 $tva_tx = (string)
get_default_tva($mysoc, $this->thirdparty, $prod->id);
498 if (empty($tva_tx)) {
503 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
504 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
508 $price = $prod->multiprices[$this->thirdparty->price_level];
510 $price = $prod->price;
515 $line->fk_product = $idproduct;
516 $line->desc = $productdesc;
518 $line->subprice = $price;
519 $line->remise_percent = $remise_percent;
520 $line->vat_src_code = $vat_src_code;
521 $line->tva_tx = $tva_tx;
522 $line->fk_unit = $prod->fk_unit;
524 $line->info_bits = 1;
527 $this->lines[] = $line;
545 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
546 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
551 $result = $remise->fetch($idremise);
554 if ($remise->fk_facture) {
555 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
556 $this->db->rollback();
562 $line->context = $this->context;
564 $line->fk_propal = $this->id;
565 $line->fk_remise_except = $remise->id;
566 $line->desc = $remise->description;
567 $line->vat_src_code = $remise->vat_src_code;
568 $line->tva_tx = $remise->tva_tx;
569 $line->subprice = -(float) $remise->amount_ht;
570 $line->fk_product = 0;
572 $line->remise_percent = 0;
574 $line->info_bits = 2;
577 $line->price = -(float) $remise->amount_ht;
579 $line->total_ht = -(float) $remise->amount_ht;
580 $line->total_tva = -(float) $remise->amount_tva;
581 $line->total_ttc = -(float) $remise->amount_ttc;
583 $result = $line->insert();
590 $this->db->rollback();
594 $this->error = $line->error;
595 $this->errors = $line->errors;
596 $this->db->rollback();
600 $this->db->rollback();
650 $remise_percent = 0.0,
651 $price_base_type =
'HT',
663 $array_options = array(),
668 $fk_remise_except = 0,
669 $noupdateafterinsertline = 0
671 global $mysoc, $langs;
673 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);
675 if ($this->
status == self::STATUS_DRAFT) {
676 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
679 if (empty($remise_percent)) {
685 if (empty($info_bits)) {
691 if (empty($fk_parent_line) || $fk_parent_line < 0) {
695 $remise_percent =
price2num($remise_percent);
698 $pu_ht_devise =
price2num($pu_ht_devise);
700 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
706 if ($price_base_type ==
'HT') {
717 if ($date_start && $date_end && $date_start > $date_end) {
718 $langs->load(
"errors");
719 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
725 $product_type = $type;
726 if (!empty($fk_product) && $fk_product > 0) {
727 $product =
new Product($this->db);
728 $result = $product->fetch($fk_product);
729 $product_type = $product->type;
731 if (
getDolGlobalString(
'STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL') && $product_type == 0 && $product->stock_reel < $qty) {
732 $langs->load(
"errors");
733 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref);
734 $this->db->rollback();
747 $tmpproduct =
new Product($this->db);
748 $result = $tmpproduct->fetch($fk_product);
749 $qtysign = ((float) $qty < 0 ? -1 : 1);
750 if (abs((
float) $qty) < (float) $tmpproduct->packaging) {
751 $qty = $qtysign * (float) $tmpproduct->packaging;
752 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
754 if (!empty($tmpproduct->packaging) && (
float)
price2num(abs((
float) $qty) - round(abs((
float) $qty) / (
float) $tmpproduct->packaging) * (
float) $tmpproduct->packaging,
'MS') != 0) {
755 $coeff = intval(abs($qty) / $tmpproduct->packaging) + 1;
756 $qty =
price2num($qtysign * (
float) $tmpproduct->packaging * $coeff,
'MS');
757 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
765 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
766 $vat_src_code = $reg[1];
767 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
770 $tabprice =
calcul_price_total($qty, (
float) $pu, (
float) $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_ht_devise);
772 $total_ht = $tabprice[0];
773 $total_tva = $tabprice[1];
774 $total_ttc = $tabprice[2];
775 $total_localtax1 = $tabprice[9];
776 $total_localtax2 = $tabprice[10];
777 $pu_ht = $tabprice[3];
778 $pu_tva = $tabprice[4];
779 $pu_ttc = $tabprice[5];
782 $multicurrency_total_ht = $tabprice[16];
783 $multicurrency_total_tva = $tabprice[17];
784 $multicurrency_total_ttc = $tabprice[18];
785 $pu_ht_devise = $tabprice[19];
789 if ($ranktouse == -1) {
790 $rangmax = $this->
line_max($fk_parent_line);
791 $ranktouse = $rangmax + 1;
798 if ((
float) $remise_percent > 0) {
799 $remise = round(((
float) $pu * (
float) $remise_percent / 100), 2);
800 $price = (float) $pu - $remise;
806 $this->line->context = $this->context;
808 $this->line->fk_propal = $this->id;
809 $this->line->label = $label;
810 $this->line->desc = $desc;
811 $this->line->qty = (float) $qty;
813 $this->line->vat_src_code = $vat_src_code;
814 $this->line->tva_tx = $txtva;
815 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
816 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
817 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
818 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
819 $this->line->fk_product = $fk_product;
820 $this->line->product_type = $type;
821 $this->line->fk_remise_except = $fk_remise_except;
822 $this->line->remise_percent = $remise_percent;
823 $this->line->subprice = (float) $pu_ht;
824 $this->line->rang = $ranktouse;
825 $this->line->info_bits = $info_bits;
826 $this->line->total_ht = (float) $total_ht;
827 $this->line->total_tva = (float) $total_tva;
828 $this->line->total_localtax1 = (float) $total_localtax1;
829 $this->line->total_localtax2 = (float) $total_localtax2;
830 $this->line->total_ttc = (float) $total_ttc;
831 $this->line->special_code = $special_code;
832 $this->line->fk_parent_line = $fk_parent_line;
833 $this->line->fk_unit = $fk_unit;
835 $this->line->date_start = $date_start;
836 $this->line->date_end = $date_end;
838 $this->line->fk_fournprice = $fk_fournprice;
839 $this->line->pa_ht = $pa_ht;
841 $this->line->origin_id = $origin_id;
842 $this->line->origin = $origin;
845 $this->line->fk_multicurrency = $this->fk_multicurrency;
846 $this->line->multicurrency_code = $this->multicurrency_code;
847 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
848 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
849 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
850 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
853 if (empty($qty) && empty($special_code)) {
854 $this->line->special_code = 3;
858 $this->line->price = $price;
860 if (is_array($array_options) && count($array_options) > 0) {
861 $this->line->array_options = $array_options;
864 $result = $this->line->insert();
866 if (!isset($this->context[
'createfromclone'])) {
867 if (!empty($fk_parent_line)) {
870 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
872 $linecount = count($this->lines);
873 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
878 $this->lines[] = $this->line;
880 foreach ($this->lines as $line) {
881 if ($line->id == $origin_id) {
882 $this->line->extraparams = $line->extraparams;
883 $this->line->setExtraParameters();
889 if (empty($noupdateafterinsertline)) {
895 return $this->line->id;
897 $this->error = $this->db->error();
898 $this->db->rollback();
902 $this->error = $this->line->error;
903 $this->errors = $this->line->errors;
904 $this->db->rollback();
908 dol_syslog(get_class($this).
"::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR);
943 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)
945 global $mysoc, $langs;
947 dol_syslog(get_class($this).
"::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent,
948 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");
949 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
952 $remise_percent =
price2num($remise_percent);
955 $pu_ht_devise =
price2num($pu_ht_devise);
956 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
962 if (empty($qty) && empty($special_code)) {
965 if (!empty($qty) && $special_code == 3) {
972 if ($date_start && $date_end && $date_start > $date_end) {
973 $langs->load(
"errors");
974 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
978 if ($this->
status == self::STATUS_DRAFT) {
991 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
992 $vat_src_code = $reg[1];
993 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1002 if ($tmpline->fetch($rowid) > 0) {
1003 $qtysign = ((float) $qty < 0 ? -1 : 1);
1004 if (abs((
float) $qty) < (float) $tmpline->packaging) {
1005 $qty = $qtysign * (float) $tmpline->packaging;
1007 if (!empty($tmpline->packaging)
1008 && is_numeric($tmpline->packaging)
1009 && (
float) $tmpline->packaging > 0
1010 && (
float)
price2num(abs((
float) $qty) - round(abs((
float) $qty) / (
float) $tmpline->packaging) * (
float) $tmpline->packaging,
'MS') != 0) {
1011 $coeff = intval(abs((
float) $qty) / $tmpline->packaging) + 1;
1012 $qty =
price2num($qtysign * (
float) $tmpline->packaging * $coeff,
'MS');
1013 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
1019 $tabprice =
calcul_price_total($qty, (
float) $pu, (
float) $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_ht_devise);
1020 $total_ht = $tabprice[0];
1021 $total_tva = $tabprice[1];
1022 $total_ttc = $tabprice[2];
1023 $total_localtax1 = $tabprice[9];
1024 $total_localtax2 = $tabprice[10];
1025 $pu_ht = $tabprice[3];
1026 $pu_tva = $tabprice[4];
1027 $pu_ttc = $tabprice[5];
1030 $multicurrency_total_ht = $tabprice[16];
1031 $multicurrency_total_tva = $tabprice[17];
1032 $multicurrency_total_ttc = $tabprice[18];
1033 $pu_ht_devise = $tabprice[19];
1038 if ((
float) $remise_percent > 0) {
1039 $remise = round(((
float) $pu * (
float) $remise_percent / 100), 2);
1040 $price = (float) $pu - $remise;
1045 $line->fetch($rowid);
1047 $staticline = clone $line;
1049 $line->oldline = $staticline;
1050 $this->line = $line;
1051 $this->line->context = $this->context;
1052 $this->line->rang = $rang;
1055 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
1056 $rangmax = $this->
line_max($fk_parent_line);
1057 $this->line->rang = $rangmax + 1;
1060 $this->line->id = $rowid;
1061 $this->line->label = $label;
1062 $this->line->desc = $desc;
1063 $this->line->qty = $qty;
1064 $this->line->product_type = $type;
1065 $this->line->vat_src_code = $vat_src_code;
1066 $this->line->tva_tx = $txtva;
1067 $this->line->localtax1_tx = $txlocaltax1;
1068 $this->line->localtax2_tx = $txlocaltax2;
1069 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
1070 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
1071 $this->line->remise_percent = $remise_percent;
1072 $this->line->subprice = (float) $pu_ht;
1073 $this->line->info_bits = $info_bits;
1075 $this->line->total_ht = (float) $total_ht;
1076 $this->line->total_tva = (float) $total_tva;
1077 $this->line->total_localtax1 = (float) $total_localtax1;
1078 $this->line->total_localtax2 = (float) $total_localtax2;
1079 $this->line->total_ttc = (float) $total_ttc;
1080 $this->line->special_code = $special_code;
1081 $this->line->fk_parent_line = $fk_parent_line;
1082 $this->line->skip_update_total = $skip_update_total;
1083 $this->line->fk_unit = $fk_unit;
1085 $this->line->fk_fournprice = $fk_fournprice;
1086 $this->line->pa_ht = $pa_ht;
1088 $this->line->date_start = $date_start;
1089 $this->line->date_end = $date_end;
1091 if (is_array($array_options) && count($array_options) > 0) {
1093 foreach ($array_options as $key => $value) {
1094 $this->line->array_options[$key] = $array_options[$key];
1099 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
1100 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
1101 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
1102 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
1104 $result = $this->line->update($notrigger);
1107 if (!empty($fk_parent_line)) {
1117 $this->db->commit();
1120 $this->error = $this->line->error;
1121 $this->errors = $this->line->errors;
1122 $this->db->rollback();
1126 dol_syslog(get_class($this).
"::updateline Erreur -2 Propal en mode incompatible pour cette action");
1143 if ($this->
status == self::STATUS_DRAFT) {
1148 $line->context = $this->context;
1151 $line->fetch($lineid);
1156 if ($id > 0 && (
int) $line->fk_propal !== (
int) $id) {
1157 $this->db->rollback();
1158 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1163 $staticline = clone $line;
1164 $line->oldline = $staticline;
1166 if ($line->delete($user) > 0) {
1169 $this->db->commit();
1172 $this->error = $line->error;
1173 $this->errors = $line->errors;
1174 $this->db->rollback();
1178 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1192 public function create($user, $notrigger = 0)
1194 global
$conf, $hookmanager, $mysoc;
1200 if (empty($this->date)) {
1201 $this->date = $this->datep;
1203 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1204 if (empty($this->availability_id)) {
1205 $this->availability_id = 0;
1207 if (empty($this->demand_reason_id)) {
1208 $this->demand_reason_id = 0;
1212 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1217 if (empty($this->fk_multicurrency)) {
1218 $this->multicurrency_code =
$conf->currency;
1219 $this->fk_multicurrency = 0;
1220 $this->multicurrency_tx = 1;
1226 $delivery_date = $this->delivery_date;
1233 $this->error =
"Failed to fetch company";
1234 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1239 if (!empty($this->
ref)) {
1242 $this->error =
'ErrorRefAlreadyExists';
1243 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1244 $this->db->rollback();
1249 if (empty($this->date)) {
1250 $this->error =
"Date of proposal is required";
1251 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1259 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
1262 $sql .=
", total_tva";
1263 $sql .=
", total_ttc";
1267 $sql .=
", fk_user_author";
1268 $sql .=
", note_private";
1269 $sql .=
", note_public";
1270 $sql .=
", model_pdf";
1271 $sql .=
", fin_validite";
1272 $sql .=
", fk_cond_reglement";
1273 $sql .=
", deposit_percent";
1274 $sql .=
", fk_mode_reglement";
1275 $sql .=
", fk_account";
1276 $sql .=
", ref_client";
1277 $sql .=
", ref_ext";
1278 $sql .=
", date_livraison";
1279 $sql .=
", fk_shipping_method";
1280 $sql .=
", fk_warehouse";
1281 $sql .=
", fk_availability";
1282 $sql .=
", fk_input_reason";
1283 $sql .=
", fk_projet";
1284 $sql .=
", fk_incoterms";
1285 $sql .=
", location_incoterms";
1287 $sql .=
", fk_multicurrency";
1288 $sql .=
", multicurrency_code";
1289 $sql .=
", multicurrency_tx";
1291 $sql .=
" VALUES (";
1292 $sql .= $this->socid;
1296 $sql .=
", '".$this->db->idate($this->date).
"'";
1297 $sql .=
", '".$this->db->idate($now).
"'";
1298 $sql .=
", '(PROV)'";
1299 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
1300 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1301 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1302 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1303 $sql .=
", ".($this->fin_validite !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
"NULL");
1304 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1305 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
'NULL');
1306 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1307 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1308 $sql .=
", '".$this->db->escape($this->ref_client).
"'";
1309 $sql .=
", '".$this->db->escape($this->ref_ext).
"'";
1310 $sql .=
", ".(!
isDolTms($delivery_date) ?
"NULL" :
"'".$this->db->idate($delivery_date).
"'");
1311 $sql .=
", ".($this->shipping_method_id > 0 ? $this->shipping_method_id :
'NULL');
1312 $sql .=
", ".($this->warehouse_id > 0 ? $this->warehouse_id :
'NULL');
1313 $sql .=
", ".((int) $this->availability_id);
1314 $sql .=
", ".((int) $this->demand_reason_id);
1315 $sql .=
", ".($this->fk_project ? $this->fk_project :
"null");
1316 $sql .=
", ".(int) $this->fk_incoterms;
1317 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1318 $sql .=
", ".(int) $this->entity;
1319 $sql .=
", ".(int) $this->fk_multicurrency;
1320 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1321 $sql .=
", ".(float) $this->multicurrency_tx;
1324 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1325 $resql = $this->db->query($sql);
1327 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
1330 $this->
ref =
'(PROV'.$this->id.
')';
1331 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1333 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1334 $resql = $this->db->query($sql);
1339 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1340 $this->linked_objects = $this->linkedObjectsIds;
1344 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1345 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1346 if (is_array($tmp_origin_id)) {
1347 foreach ($tmp_origin_id as $origin_id) {
1350 $this->error = $this->db->lasterror();
1355 $origin_id = $tmp_origin_id;
1358 $this->error = $this->db->lasterror();
1370 $fk_parent_line = 0;
1371 $num = count($this->lines);
1373 for ($i = 0; $i < $num; $i++) {
1374 if (!is_object($this->lines[$i])) {
1376 $line = (object) $this->lines[$i];
1378 $line = $this->lines[$i];
1381 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1382 $fk_parent_line = 0;
1385 $vatrate = $line->tva_tx;
1386 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', $vatrate)) {
1387 $vatrate .=
' ('.$line->vat_src_code.
')';
1391 $originid = $line->origin_id;
1392 $origintype = $line->origin;
1394 $originid = $line->id;
1395 $origintype = $this->element;
1403 $line->localtax1_tx,
1404 $line->localtax2_tx,
1406 $line->remise_percent,
1410 $line->product_type,
1412 $line->special_code,
1414 $line->fk_fournprice,
1419 $line->array_options,
1421 (
string) $origintype,
1430 $this->error = $this->db->error;
1436 $line->id = $result;
1439 if ($result > 0 && $line->product_type == 9) {
1440 $fk_parent_line = $result;
1470 if (!$error && !$notrigger) {
1479 $this->error = $this->db->lasterror();
1484 $this->error = $this->db->lasterror();
1489 $this->db->commit();
1490 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1493 $this->db->rollback();
1497 $this->error = $this->db->lasterror();
1498 $this->db->rollback();
1513 public function createFromClone(
User $user, $socid = 0, $forceentity =
null, $update_prices =
false, $update_desc =
false)
1515 global
$conf, $hookmanager, $mysoc;
1524 $object =
new self($this->db);
1531 $objsoc =
new Societe($this->db);
1534 if (!empty($socid) && $socid !=
$object->socid) {
1535 if ($objsoc->fetch($socid) > 0) {
1537 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1538 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
null);
1539 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1540 $object->fk_delivery_address = 0;
1563 $objsoc->fetch(
$object->socid);
1567 if ($update_prices ===
true || $update_desc ===
true) {
1568 if ($objsoc->id > 0 && !empty(
$object->lines)) {
1571 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1574 foreach (
$object->lines as $line) {
1577 if ($line->fk_product > 0) {
1578 $prod =
new Product($this->db);
1579 $res = $prod->fetch($line->fk_product);
1581 if ($update_prices ===
true) {
1582 $pu_ht = $prod->price;
1584 $remise_percent = $objsoc->remise_percent;
1587 $pu_ht = $prod->multiprices[$objsoc->price_level];
1589 if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) {
1590 $tva_tx = (string) $prod->multiprices_tva_tx[$objsoc->price_level];
1595 $filter = array(
't.fk_product' => (
string) $prod->id,
't.fk_soc' => (
string) $objsoc->id);
1596 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1599 if (count($prodcustprice->lines) > 0) {
1600 $date_now = (int) floor(
dol_now() / 86400) * 86400;
1601 foreach ($prodcustprice->lines as $k => $custprice_line) {
1602 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
1603 $pu_ht =
price($custprice_line->price);
1604 $tva_tx = ($custprice_line->default_vat_code ? $custprice_line->tva_tx .
' (' . $custprice_line->default_vat_code .
' )' : $custprice_line->tva_tx);
1605 if ($custprice_line->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1606 $tva_tx .=
' (' . $custprice_line->default_vat_code .
')';
1608 $remise_percent = $custprice_line->discount_percent;
1616 $line->subprice = $pu_ht;
1617 $line->tva_tx = $tva_tx;
1618 $line->remise_percent = $remise_percent;
1621 if ($line->fk_fournprice > 0) {
1622 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1624 if ($prodfourn->fetch_product_fournisseur_price($line->fk_fournprice) > 0) {
1625 $line->pa_ht =
price2num($prodfourn->fourn_unitprice * (1 - $prodfourn->fourn_remise_percent / 100),
'MU');
1627 $line->fk_fournprice = 0;
1631 if ($update_desc ===
true) {
1632 $line->desc = $prod->description;
1642 $object->entity = (!empty($forceentity) ? $forceentity :
$object->entity);
1647 $object->user_creation_id = $user->id;
1648 $object->user_validation_id = 0;
1661 $object->context[
'createfromclone'] =
'createfromclone';
1662 $result =
$object->create($user);
1664 $this->error =
$object->error;
1665 $this->errors = array_merge($this->errors,
$object->errors);
1671 if (
$object->copy_linked_contact($this,
'internal') < 0) {
1678 if ($this->socid ==
$object->socid) {
1679 if (
$object->copy_linked_contact($this,
'external') < 0) {
1687 if (is_object($hookmanager)) {
1688 $parameters = array(
'objFrom' => $this,
'clonedObj' =>
$object);
1690 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1698 unset(
$object->context[
'createfromclone']);
1702 $this->db->commit();
1705 $this->db->rollback();
1719 public function fetch($rowid, $ref =
'', $ref_ext =
'', $forceentity = 0)
1721 $sql =
"SELECT p.rowid, p.ref, p.entity, p.fk_soc";
1722 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1723 $sql .=
", p.datec";
1724 $sql .=
", p.date_signature as dates";
1725 $sql .=
", p.date_valid as datev";
1726 $sql .=
", p.datep as dp";
1727 $sql .=
", p.fin_validite as dfv";
1728 $sql .=
", p.date_livraison as delivery_date";
1729 $sql .=
", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
1730 $sql .=
", p.note_private, p.note_public";
1731 $sql .=
", p.fk_projet as fk_project, p.fk_statut";
1732 $sql .=
", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1733 $sql .=
", p.fk_delivery_address";
1734 $sql .=
", p.fk_availability";
1735 $sql .=
", p.fk_input_reason";
1736 $sql .=
", p.fk_cond_reglement";
1737 $sql .=
", p.fk_mode_reglement";
1738 $sql .=
', p.fk_account';
1739 $sql .=
", p.fk_shipping_method";
1740 $sql .=
", p.fk_warehouse";
1741 $sql .=
", p.fk_incoterms, p.location_incoterms";
1742 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1743 $sql .=
", p.tms as date_modification";
1744 $sql .=
", i.libelle as label_incoterms";
1745 $sql .=
", c.label as statut_label";
1746 $sql .=
", ca.code as availability_code, ca.label as availability";
1747 $sql .=
", dr.code as demand_reason_code, dr.label as demand_reason";
1748 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1749 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1750 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
1751 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_propalst as c ON p.fk_statut = c.id';
1752 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.
getEntity(
'c_paiement').
')';
1753 $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').
')';
1754 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON p.fk_availability = ca.rowid';
1755 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
1756 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON p.fk_incoterms = i.rowid';
1759 if (!empty($forceentity)) {
1760 $sql .=
" WHERE p.entity = ".(int) $forceentity;
1762 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
1764 $sql .=
" AND p.ref='".$this->db->escape($ref).
"'";
1767 $sql .=
" WHERE p.rowid = ".((int) $rowid);
1770 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1771 $resql = $this->db->query($sql);
1773 if ($this->db->num_rows($resql)) {
1774 $obj = $this->db->fetch_object($resql);
1776 $this->
id = $obj->rowid;
1777 $this->entity = $obj->entity;
1779 $this->
ref = $obj->ref;
1780 $this->ref_client = $obj->ref_client;
1781 $this->ref_customer = $obj->ref_client;
1782 $this->ref_ext = $obj->ref_ext;
1784 $this->total = $obj->total_ttc;
1785 $this->total_ttc = $obj->total_ttc;
1786 $this->total_ht = $obj->total_ht;
1787 $this->total_tva = $obj->total_tva;
1788 $this->total_localtax1 = $obj->localtax1;
1789 $this->total_localtax2 = $obj->localtax2;
1791 $this->socid = $obj->fk_soc;
1792 $this->thirdparty =
null;
1794 $this->fk_project = $obj->fk_project;
1795 $this->project =
null;
1797 $this->model_pdf = $obj->model_pdf;
1798 $this->last_main_doc = $obj->last_main_doc;
1799 $this->note = $obj->note_private;
1800 $this->note_private = $obj->note_private;
1801 $this->note_public = $obj->note_public;
1803 $this->
status = (int) $obj->fk_statut;
1804 $this->statut = $this->status;
1806 $this->datec = $this->db->jdate($obj->datec);
1807 $this->datev = $this->db->jdate($obj->datev);
1808 $this->date_creation = $this->db->jdate($obj->datec);
1809 $this->date_validation = $this->db->jdate($obj->datev);
1810 $this->date_modification = $this->db->jdate($obj->date_modification);
1811 $this->date_signature = $this->db->jdate($obj->dates);
1812 $this->date = $this->db->jdate($obj->dp);
1813 $this->datep = $this->db->jdate($obj->dp);
1814 $this->fin_validite = $this->db->jdate($obj->dfv);
1815 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1816 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1817 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
1818 $this->availability_id = $obj->fk_availability;
1819 $this->availability_code = $obj->availability_code;
1821 $this->demand_reason_id = $obj->fk_input_reason;
1822 $this->demand_reason_code = $obj->demand_reason_code;
1824 $this->fk_address = $obj->fk_delivery_address;
1826 $this->mode_reglement_id = $obj->fk_mode_reglement;
1827 $this->mode_reglement_code = $obj->mode_reglement_code;
1828 $this->mode_reglement = $obj->mode_reglement;
1829 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1830 $this->cond_reglement_id = $obj->fk_cond_reglement;
1831 $this->cond_reglement_code = $obj->cond_reglement_code;
1832 $this->cond_reglement = $obj->cond_reglement;
1833 $this->cond_reglement_label = $obj->cond_reglement;
1834 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1835 $this->deposit_percent = $obj->deposit_percent;
1837 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1839 $this->user_author_id = $obj->fk_user_author;
1840 $this->user_validation_id = $obj->fk_user_valid;
1841 $this->user_closing_id = $obj->fk_user_cloture;
1844 $this->fk_incoterms = $obj->fk_incoterms;
1845 $this->location_incoterms = $obj->location_incoterms;
1846 $this->label_incoterms = $obj->label_incoterms;
1849 $this->fk_multicurrency = $obj->fk_multicurrency;
1850 $this->multicurrency_code = $obj->multicurrency_code;
1851 $this->multicurrency_tx = $obj->multicurrency_tx;
1852 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1853 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1854 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1860 $this->db->free($resql);
1862 $this->lines = array();
1873 $this->error =
"Record Not Found";
1876 $this->error = $this->db->lasterror();
1895 if (isset($this->
ref)) {
1896 $this->
ref = trim($this->
ref);
1898 if (isset($this->ref_client)) {
1899 $this->ref_client = trim($this->ref_client);
1901 if (isset($this->note) || isset($this->note_private)) {
1902 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1904 if (isset($this->note_public)) {
1905 $this->note_public = trim($this->note_public);
1907 if (isset($this->model_pdf)) {
1908 $this->model_pdf = trim($this->model_pdf);
1910 if (isset($this->import_key)) {
1911 $this->import_key = trim($this->import_key);
1913 if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
1914 $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
1921 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1922 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET";
1923 $sql .=
" ref = ".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1924 $sql .=
" ref_client = ".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
1925 $sql .=
" ref_ext = ".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1926 $sql .=
" fk_soc = ".(!empty($this->socid) ? (int) $this->socid :
"null").
",";
1927 $sql .=
" datep = ".(strval($this->date) !=
'' ?
"'".$this->db->idate($this->date).
"'" :
'null').
",";
1928 if (!empty($this->fin_validite)) {
1929 $sql .=
" fin_validite = ".(strval($this->fin_validite) !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
'null').
",";
1931 $sql .=
" date_valid = ".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1932 $sql .=
" total_tva = ".(isset($this->total_tva) ? (float) $this->total_tva :
"null").
",";
1933 $sql .=
" localtax1 = ".(isset($this->total_localtax1) ? (float) $this->total_localtax1 :
"null").
",";
1934 $sql .=
" localtax2 = ".(isset($this->total_localtax2) ? (float) $this->total_localtax2 :
"null").
",";
1935 $sql .=
" total_ht = ".(isset($this->total_ht) ? (float) $this->total_ht :
"null").
",";
1936 $sql .=
" total_ttc = ".(isset($this->total_ttc) ? (float) $this->total_ttc :
"null").
",";
1937 $sql .=
" fk_statut = ".(isset($this->
status) ? (int) $this->
status :
"null").
",";
1938 $sql .=
" fk_user_author = ".(!empty($this->user_author_id) ? (int) $this->user_author_id :
"null").
",";
1939 $sql .=
" fk_user_valid = ".(!empty($this->user_validation_id) ? (int) $this->user_validation_id :
"null").
",";
1941 $sql .=
" fk_projet = ".(!empty($this->fk_project) ? (int) $this->fk_project :
"null").
",";
1942 $sql .=
" fk_cond_reglement = ".(!empty($this->cond_reglement_id) ? (int) $this->cond_reglement_id :
"null").
",";
1943 $sql .=
" deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1944 $sql .=
" fk_mode_reglement = ".(!empty($this->mode_reglement_id) ? (int) $this->mode_reglement_id :
"null").
",";
1945 $sql .=
" fk_input_reason = ".(!empty($this->demand_reason_id) ? (int) $this->demand_reason_id :
"null").
",";
1946 $sql .=
" fk_shipping_method=".(isset($this->shipping_method_id) ? (int) $this->shipping_method_id :
"null").
",";
1947 $sql .=
" fk_availability=".(isset($this->availability_id) ? (int) $this->availability_id :
"null").
",";
1948 $sql .=
" note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1949 $sql .=
" note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1950 $sql .=
" model_pdf = ".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1951 $sql .=
" import_key = ".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1952 $sql .=
" WHERE rowid = ".((int) $this->
id);
1956 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1957 $resql = $this->db->query($sql);
1960 $this->errors[] =
"Error ".$this->db->lasterror();
1970 if (!$error && !$notrigger) {
1981 foreach ($this->errors as $errmsg) {
1982 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1983 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1985 $this->db->rollback();
1988 $this->db->commit();
2003 public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $sqlforgedfilters =
'')
2006 $this->lines = array();
2008 $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,';
2009 $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,';
2010 $sql .=
' d.fk_unit,';
2011 $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,';
2012 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units,';
2013 $sql .=
' d.date_start, d.date_end, d.extraparams,';
2014 $sql .=
' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc';
2015 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as d';
2016 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (d.fk_product = p.rowid)';
2017 $sql .=
' WHERE d.fk_propal = '.((int) $this->
id);
2018 if ($only_product) {
2019 $sql .=
' AND p.fk_product_type = 0';
2021 if ($sqlforgedfilters) {
2022 $sql .= $sqlforgedfilters;
2024 $sql .=
' ORDER by d.rang';
2026 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
2027 $result = $this->db->query($sql);
2029 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
2031 $num = $this->db->num_rows($result);
2035 $objp = $this->db->fetch_object($result);
2039 $line->rowid = $objp->rowid;
2040 $line->id = $objp->rowid;
2041 $line->fk_propal = $objp->fk_propal;
2042 $line->fk_parent_line = $objp->fk_parent_line;
2043 $line->product_type = $objp->product_type;
2044 $line->label = $objp->custom_label;
2045 $line->desc = $objp->description;
2046 $line->description = $objp->description;
2047 $line->qty = $objp->qty;
2048 $line->vat_src_code = $objp->vat_src_code;
2049 $line->tva_tx = $objp->tva_tx;
2050 $line->localtax1_tx = $objp->localtax1_tx;
2051 $line->localtax2_tx = $objp->localtax2_tx;
2052 $line->localtax1_type = $objp->localtax1_type;
2053 $line->localtax2_type = $objp->localtax2_type;
2054 $line->subprice = $objp->subprice;
2055 $line->fk_remise_except = $objp->fk_remise_except;
2056 $line->remise_percent = $objp->remise_percent;
2057 $line->price = $objp->price;
2059 $line->info_bits = $objp->info_bits;
2060 $line->total_ht = $objp->total_ht;
2061 $line->total_tva = $objp->total_tva;
2062 $line->total_localtax1 = $objp->total_localtax1;
2063 $line->total_localtax2 = $objp->total_localtax2;
2064 $line->total_ttc = $objp->total_ttc;
2065 $line->fk_fournprice = $objp->fk_fournprice;
2066 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
2067 $line->pa_ht = $marginInfos[0];
2068 $line->marge_tx = $marginInfos[1];
2069 $line->marque_tx = $marginInfos[2];
2070 $line->special_code = $objp->special_code;
2071 $line->rang = $objp->rang;
2073 $line->fk_product = $objp->fk_product;
2075 $line->ref = $objp->product_ref;
2076 $line->libelle = $objp->product_label;
2078 $line->product_ref = $objp->product_ref;
2079 $line->product_label = $objp->product_label;
2080 $line->product_desc = $objp->product_desc;
2081 $line->product_tobatch = $objp->product_tobatch;
2082 $line->product_barcode = $objp->product_barcode;
2084 $line->fk_product_type = $objp->fk_product_type;
2085 $line->fk_unit = $objp->fk_unit;
2086 $line->weight = $objp->weight;
2087 $line->weight_units = $objp->weight_units;
2088 $line->volume = $objp->volume;
2089 $line->volume_units = $objp->volume_units;
2091 $line->date_start = $this->db->jdate($objp->date_start);
2092 $line->date_end = $this->db->jdate($objp->date_end);
2094 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
2097 $line->fk_multicurrency = $objp->fk_multicurrency;
2098 $line->multicurrency_code = $objp->multicurrency_code;
2099 $line->multicurrency_subprice = $objp->multicurrency_subprice;
2100 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
2101 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
2102 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2104 $line->fetch_optionals();
2107 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
2108 $tmpproduct =
new Product($this->db);
2109 $tmpproduct->fetch($objp->fk_product);
2110 $tmpproduct->getMultiLangs();
2112 $line->multilangs = $tmpproduct->multilangs;
2115 $this->lines[$i] = $line;
2120 $this->db->free($result);
2124 $this->error = $this->db->lasterror();
2136 public function valid($user, $notrigger = 0)
2140 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2145 if ($this->
status == self::STATUS_VALIDATED) {
2146 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
2150 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'creer'))
2151 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'propal_advance',
'validate')))) {
2152 $this->error =
'ErrorPermissionDenied';
2153 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
2162 $soc =
new Societe($this->db);
2163 $soc->fetch($this->socid);
2166 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
2173 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2174 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
2175 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
", date_valid='".$this->db->idate($now).
"', fk_user_valid=".((int) $user->id);
2178 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
2179 $resql = $this->db->query($sql);
2186 if (!$error && !$notrigger) {
2188 $result = $this->
call_trigger(
'PROPAL_VALIDATE', $user);
2196 $this->oldref = $this->ref;
2199 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
2201 $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).
"'";
2202 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
2203 $resql = $this->db->query($sql);
2206 $this->error = $this->db->lasterror();
2208 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'propale/".$this->db->escape($this->newref).
"'";
2209 $sql .=
" WHERE filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
2210 $resql = $this->db->query($sql);
2213 $this->error = $this->db->lasterror();
2219 $dirsource =
$conf->propal->multidir_output[$this->entity].
'/'.$oldref;
2220 $dirdest =
$conf->propal->multidir_output[$this->entity].
'/'.$newref;
2221 if (!$error && file_exists($dirsource)) {
2222 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
2223 if (@rename($dirsource, $dirdest)) {
2226 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
2227 foreach ($listoffiles as $fileentry) {
2228 $dirsource = $fileentry[
'name'];
2229 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
2230 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
2231 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
2232 @rename($dirsource, $dirdest);
2240 $this->user_validation_id = $user->id;
2241 $this->datev = $now;
2242 $this->date_validation = $now;
2244 $this->db->commit();
2247 $this->db->rollback();
2266 $this->error =
'ErrorBadParameter';
2267 dol_syslog(get_class($this).
"::set_date ".$this->error, LOG_ERR);
2271 if ($user->hasRight(
'propal',
'creer')) {
2276 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2277 $sql .=
" SET datep = '".$this->db->idate($date).
"'";
2278 $sql .=
" WHERE rowid = ".((int) $this->
id);
2281 $resql = $this->db->query($sql);
2283 $this->errors[] = $this->db->error();
2288 $this->oldcopy = clone $this;
2289 $this->date = $date;
2290 $this->datep = $date;
2293 if (!$notrigger && empty($error)) {
2303 $this->db->commit();
2306 foreach ($this->errors as $errmsg) {
2307 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2308 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2310 $this->db->rollback();
2330 if ($user->hasRight(
'propal',
'creer')) {
2335 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2336 $sql .=
" SET fin_validite = ".($date_end_validity !=
'' ?
"'".$this->db->idate($date_end_validity).
"'" :
'null');
2337 $sql .=
" WHERE rowid = ".((int) $this->
id);
2341 $resql = $this->db->query($sql);
2343 $this->errors[] = $this->db->error();
2349 $this->oldcopy = clone $this;
2350 $this->fin_validite = $date_end_validity;
2353 if (!$notrigger && empty($error)) {
2363 $this->db->commit();
2366 foreach ($this->errors as $errmsg) {
2367 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2368 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2370 $this->db->rollback();
2404 if ($user->hasRight(
'propal',
'creer')) {
2409 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2410 $sql .=
" SET date_livraison = ".(isDolTms($delivery_date) ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2411 $sql .=
" WHERE rowid = ".((int) $this->
id);
2414 $resql = $this->db->query($sql);
2416 $this->errors[] = $this->db->error();
2421 $this->oldcopy = clone $this;
2422 $this->delivery_date = $delivery_date;
2425 if (!$notrigger && empty($error)) {
2435 $this->db->commit();
2438 foreach ($this->errors as $errmsg) {
2439 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2440 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2442 $this->db->rollback();
2462 if ($user->hasRight(
'propal',
'creer') && $this->status >= self::STATUS_DRAFT) {
2467 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2468 $sql .=
" SET fk_availability = ".((int) $id);
2469 $sql .=
" WHERE rowid = ".((int) $this->
id);
2471 dol_syslog(__METHOD__.
' availability('.$id.
')', LOG_DEBUG);
2472 $resql = $this->db->query($sql);
2474 $this->errors[] = $this->db->error();
2479 $this->oldcopy = clone $this;
2480 $this->fk_availability = $id;
2481 $this->availability_id = $id;
2484 if (!$notrigger && empty($error)) {
2494 $this->db->commit();
2497 foreach ($this->errors as $errmsg) {
2498 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2499 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2501 $this->db->rollback();
2505 $error_str =
'Propal status do not meet requirement '.$this->status;
2507 $this->error = $error_str;
2508 $this->errors[] = $this->error;
2525 if ($user->hasRight(
'propal',
'creer') && $this->status >= self::STATUS_DRAFT) {
2530 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2531 $sql .=
" SET fk_input_reason = ".((int) $id);
2532 $sql .=
" WHERE rowid = ".((int) $this->
id);
2535 $resql = $this->db->query($sql);
2537 $this->errors[] = $this->db->error();
2543 $this->oldcopy = clone $this;
2545 $this->demand_reason_id = $id;
2549 if (!$notrigger && empty($error)) {
2559 $this->db->commit();
2562 foreach ($this->errors as $errmsg) {
2563 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2564 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2566 $this->db->rollback();
2570 $error_str =
'Propal status do not meet requirement '.$this->status;
2572 $this->error = $error_str;
2573 $this->errors[] = $this->error;
2590 if ($user->hasRight(
'propal',
'creer')) {
2595 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2596 $sql .=
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
2597 $sql .=
" WHERE rowid = ".((int) $this->
id);
2599 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
2600 $resql = $this->db->query($sql);
2602 $this->errors[] = $this->db->error();
2607 $this->oldcopy = clone $this;
2608 $this->ref_client = $ref_client;
2611 if (!$notrigger && empty($error)) {
2621 $this->db->commit();
2624 foreach ($this->errors as $errmsg) {
2625 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2626 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2628 $this->db->rollback();
2646 public function reopen($user, $status, $note =
'', $notrigger = 0)
2650 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2651 $sql .=
" SET fk_statut = ".((int) $status).
",";
2652 if (!empty($note)) {
2653 $sql .=
" note_private = '".$this->db->escape($note).
"',";
2655 $sql .=
" date_cloture=NULL, fk_user_cloture=NULL";
2656 $sql .=
" WHERE rowid = ".((int) $this->
id);
2660 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
2661 $resql = $this->db->query($sql);
2664 $this->errors[] =
"Error ".$this->db->lasterror();
2679 if (!empty($this->errors)) {
2680 foreach ($this->errors as $errmsg) {
2681 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2682 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2685 $this->db->rollback();
2688 $this->statut = $status;
2691 $this->db->commit();
2706 public function closeProposal($user, $status, $note_private =
'', $notrigger = 0, $note_public =
'')
2708 global $langs,
$conf;
2715 $newprivatenote =
dol_concatdesc($this->note_private, $note_private);
2716 $newpublicnote =
dol_concatdesc($this->note_public, $note_public);
2719 $date_signature = $now;
2720 $fk_user_signature = $user->id;
2722 $this->
info($this->
id);
2723 if (!isset($this->date_signature) || $this->date_signature ==
'') {
2724 $date_signature = $now;
2725 $fk_user_signature = $user->id;
2727 $date_signature = $this->date_signature;
2728 $fk_user_signature = $this->user_signature->id;
2732 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2733 $sql .=
" SET fk_statut = ".((int) $status).
", note_private = '".$this->db->escape($newprivatenote).
"', note_public = '".$this->db->escape($newpublicnote).
"'";
2734 if ($status == self::STATUS_SIGNED) {
2735 $sql .=
", date_signature='".$this->db->idate($now).
"', fk_user_signature = ".($fk_user_signature);
2737 $sql .=
" WHERE rowid = ".((int) $this->
id);
2739 $resql = $this->db->query($sql);
2743 $triggerName =
'PROPAL_CLOSE_REFUSED';
2745 if ($status == self::STATUS_SIGNED) {
2746 $triggerName =
'PROPAL_CLOSE_SIGNED';
2750 $soc =
new Societe($this->db);
2751 $soc->id = $this->socid;
2752 $result = $soc->setAsCustomer();
2755 $this->error = $this->db->lasterror();
2756 $this->db->rollback();
2763 $outputlangs = $langs;
2766 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2767 $outputlangs->setDefaultLang($newlang);
2776 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2780 $this->oldcopy = clone $this;
2781 $this->statut = $status;
2783 $this->date_signature = $date_signature;
2784 $this->note_private = $newprivatenote;
2787 if (!$notrigger && empty($error)) {
2797 $this->db->commit();
2800 foreach ($this->errors as $errmsg) {
2801 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2802 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2804 if (!empty($this->oldcopy)) {
2805 $this->statut = $this->oldcopy->status;
2806 $this->
status = $this->oldcopy->status;
2807 $this->date_signature = $this->oldcopy->date_signature;
2808 $this->note_private = $this->oldcopy->note_private;
2811 $this->db->rollback();
2815 $this->error = $this->db->lasterror();
2816 $this->db->rollback();
2831 global
$conf, $langs;
2838 $triggerName =
'PROPAL_CLASSIFY_BILLED';
2844 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2845 $sql .=
" SET fk_statut = ".self::STATUS_BILLED.
", ";
2846 $sql .=
" note_private = '".$this->db->escape($newprivatenote).
"', date_cloture='".$this->db->idate($now).
"', fk_user_cloture=".((int) $user->id);
2847 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_SIGNED);
2850 $resql = $this->db->query($sql);
2852 $this->errors[] = $this->db->error();
2855 $num = $this->db->affected_rows($resql);
2863 $outputlangs = $langs;
2866 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2867 $outputlangs->setDefaultLang($newlang);
2876 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2879 $this->oldcopy = clone $this;
2882 $this->date_cloture = $now;
2883 $this->note_private = $newprivatenote;
2886 if (!$notrigger && empty($error)) {
2896 $this->db->commit();
2899 foreach ($this->errors as $errmsg) {
2900 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2901 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2903 $this->db->rollback();
2920 $sql =
"UPDATE ". MAIN_DB_PREFIX . $this->table_element;
2921 $sql .=
" SET fk_statut = " . self::STATUS_CANCELED .
",";
2922 $sql .=
" fk_user_modif = " . ((int) $user->id);
2923 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2925 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
2926 if ($this->db->query($sql)) {
2939 $this->db->commit();
2942 foreach ($this->errors as $errmsg) {
2943 dol_syslog(get_class($this).
"::cancel ".$errmsg, LOG_ERR);
2944 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2946 $this->db->rollback();
2950 $this->error = $this->db->error();
2951 $this->db->rollback();
2970 if ($this->
status <= self::STATUS_DRAFT) {
2974 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
2978 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2979 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2980 $sql .=
", online_sign_ip = NULL , online_sign_name = NULL";
2981 $sql .=
" WHERE rowid = ".((int) $this->
id);
2983 $resql = $this->db->query($sql);
2985 $this->errors[] = $this->db->error();
2990 $this->oldcopy = clone $this;
2993 if (!$notrigger && empty($error)) {
3006 $this->db->commit();
3009 foreach ($this->errors as $errmsg) {
3010 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3011 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3013 $this->db->rollback();
3033 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datep', $sortorder =
'DESC')
3040 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
3041 $sql .=
" p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
3042 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
3043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.$this->table_element.
" as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
3044 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3045 $sql .=
" AND p.fk_soc = s.rowid";
3046 $sql .=
" AND p.fk_statut = c.id";
3050 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3051 $search_sale = $user->id;
3054 if ($search_sale && $search_sale !=
'-1') {
3055 if ($search_sale == -2) {
3056 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3057 } elseif ($search_sale > 0) {
3058 $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).
")";
3063 $sql .=
" AND p.fk_soc = ".((int) $socid);
3066 $sql .=
" AND p.fk_statut = ".((int) self::STATUS_DRAFT);
3068 if ($notcurrentuser > 0) {
3069 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
3071 $sql .= $this->db->order($sortfield, $sortorder);
3072 $sql .= $this->db->plimit($limit, $offset);
3074 $result = $this->db->query($sql);
3076 $num = $this->db->num_rows($result);
3080 $obj = $this->db->fetch_object($result);
3082 if ($shortlist == 1) {
3083 $ga[$obj->propalid] = $obj->ref;
3084 } elseif ($shortlist == 2) {
3085 $ga[$obj->propalid] = $obj->ref.
' ('.$obj->name.
')';
3087 $ga[$i][
'id'] = $obj->propalid;
3088 $ga[$i][
'ref'] = $obj->ref;
3089 $ga[$i][
'name'] = $obj->name;
3123 $linkedInvoices = array();
3126 foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
3129 foreach ($objectid as $key =>
$object) {
3131 if ($objecttype ==
'facture') {
3136 foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
3137 foreach ($subobjectid as $subkey => $subobject) {
3138 if ($subobjecttype ==
'facture') {
3139 $linkedInvoices[] = $subobject;
3147 if (count($linkedInvoices) > 0) {
3148 $sql =
"SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye";
3149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
3150 $sql .=
" WHERE rowid IN (".$this->db->sanitize(implode(
',', $linkedInvoices)).
")";
3152 dol_syslog(get_class($this).
"::InvoiceArrayList", LOG_DEBUG);
3153 $resql = $this->db->query($sql);
3156 $tab_sqlobj = array();
3157 $nump = $this->db->num_rows($resql);
3158 for ($i = 0; $i < $nump; $i++) {
3159 $sqlobj = $this->db->fetch_object($resql);
3160 $tab_sqlobj[] = $sqlobj;
3162 $this->db->free($resql);
3164 $nump = count($tab_sqlobj);
3168 while ($i < $nump) {
3169 $obj = array_shift($tab_sqlobj);
3192 public function delete($user, $notrigger = 0)
3195 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3211 if (!$error && !empty($this->table_element_line)) {
3212 $tabletodelete = $this->table_element_line;
3213 $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).
")";
3214 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3215 if (!$this->db->query($sqlef) || !$this->db->query($sql)) {
3217 $this->error = $this->db->lasterror();
3218 $this->errors[] = $this->error;
3219 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3244 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3250 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3251 $res = $this->db->query($sql);
3254 $this->error = $this->db->lasterror();
3255 $this->errors[] = $this->error;
3256 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3272 if ($conf->propal->multidir_output[$this->entity] && !empty($this->
ref)) {
3273 $dir =
$conf->propal->multidir_output[$this->entity].
"/".$ref;
3274 $file = $dir.
"/".$ref.
".pdf";
3275 if (file_exists($file)) {
3279 $this->error =
'ErrorFailToDeleteFile';
3280 $this->errors[] = $this->error;
3281 $this->db->rollback();
3285 if (file_exists($dir)) {
3288 $this->error =
'ErrorFailToDeleteDir';
3289 $this->errors[] = $this->error;
3290 $this->db->rollback();
3298 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3299 $this->db->commit();
3302 $this->db->rollback();
3319 if ($this->
status >= self::STATUS_DRAFT) {
3324 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
3325 $sql .=
' SET fk_availability = '.((int) $availability_id);
3326 $sql .=
' WHERE rowid='.((int) $this->
id);
3328 dol_syslog(__METHOD__.
' availability('.$availability_id.
')', LOG_DEBUG);
3329 $resql = $this->db->query($sql);
3331 $this->errors[] = $this->db->error();
3336 $this->oldcopy = clone $this;
3337 $this->availability_id = $availability_id;
3340 if (!$notrigger && empty($error)) {
3350 $this->db->commit();
3353 foreach ($this->errors as $errmsg) {
3354 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3355 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3357 $this->db->rollback();
3361 $error_str =
'Propal status do not meet requirement '.$this->status;
3363 $this->error = $error_str;
3364 $this->errors[] = $this->error;
3383 if ($this->
status >= self::STATUS_DRAFT) {
3388 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
3389 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
3390 $sql .=
' WHERE rowid='.((int) $this->
id);
3392 dol_syslog(__METHOD__.
' demand_reason('.$demand_reason_id.
')', LOG_DEBUG);
3393 $resql = $this->db->query($sql);
3395 $this->errors[] = $this->db->error();
3400 $this->oldcopy = clone $this;
3401 $this->demand_reason_id = $demand_reason_id;
3404 if (!$notrigger && empty($error)) {
3414 $this->db->commit();
3417 foreach ($this->errors as $errmsg) {
3418 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3419 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3421 $this->db->rollback();
3425 $error_str =
'Propal status do not meet requirement '.$this->status;
3427 $this->error = $error_str;
3428 $this->errors[] = $this->error;
3442 $sql =
"SELECT c.rowid, ";
3443 $sql .=
" c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,";
3444 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
3445 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as c";
3446 $sql .=
" WHERE c.rowid = ".((int) $id);
3448 $result = $this->db->query($sql);
3451 if ($this->db->num_rows($result)) {
3452 $obj = $this->db->fetch_object($result);
3454 $this->
id = $obj->rowid;
3456 $this->date_creation = $this->db->jdate($obj->datec);
3457 $this->date_validation = $this->db->jdate($obj->datev);
3458 $this->date_signature = $this->db->jdate($obj->date_signature);
3459 $this->date_cloture = $this->db->jdate($obj->date_cloture);
3461 $this->user_creation_id = $obj->fk_user_author;
3462 $this->user_validation_id = $obj->fk_user_valid;
3464 if ($obj->fk_user_signature) {
3465 $user_signature =
new User($this->db);
3466 $user_signature->fetch($obj->fk_user_signature);
3467 $this->user_signature = $user_signature;
3470 $this->user_closing_id = $obj->fk_user_cloture;
3472 $this->db->free($result);
3501 global $hookmanager;
3504 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3506 $langs->load(
"propal");
3507 $this->labelStatus[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceled");
3508 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraft");
3509 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidated");
3510 $this->labelStatus[2] = $langs->transnoentitiesnoconv(
"PropalStatusSigned");
3511 $this->labelStatus[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSigned");
3512 $this->labelStatus[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilled");
3513 $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceledShort");
3514 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraftShort");
3515 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidatedShort");
3516 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv(
"PropalStatusSignedShort");
3517 $this->labelStatusShort[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSignedShort");
3518 $this->labelStatusShort[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilledShort");
3522 if ($status == self::STATUS_CANCELED) {
3523 $statusType =
'status9';
3524 } elseif ($status == self::STATUS_DRAFT) {
3525 $statusType =
'status0';
3526 } elseif ($status == self::STATUS_VALIDATED) {
3527 $statusType =
'status1';
3528 } elseif ($status == self::STATUS_SIGNED) {
3529 $statusType =
'status4';
3530 } elseif ($status == self::STATUS_NOTSIGNED) {
3531 $statusType =
'status9';
3532 } elseif ($status == self::STATUS_BILLED) {
3533 $statusType =
'status6';
3536 $parameters = array(
'status' => $status,
'mode' => $mode);
3537 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3540 return $hookmanager->resPrint;
3543 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3558 global
$conf, $langs;
3560 $sql =
"SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
3561 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
3562 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3563 if ($mode ==
'opened') {
3564 $sql .=
" AND p.fk_statut = ".self::STATUS_VALIDATED;
3566 if ($mode ==
'signed') {
3567 $sql .=
" AND p.fk_statut = ".self::STATUS_SIGNED;
3571 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3572 $search_sale = $user->id;
3575 if ($search_sale && $search_sale !=
'-1') {
3576 if ($search_sale == -2) {
3577 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3578 } elseif ($search_sale > 0) {
3579 $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).
")";
3583 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3586 $resql = $this->db->query($sql);
3588 $langs->load(
"propal");
3593 $label = $labelShort =
'';
3594 if ($mode ==
'opened') {
3595 $delay_warning =
$conf->propal->cloture->warning_delay;
3597 $label = $langs->transnoentitiesnoconv(
"PropalsToClose");
3598 $labelShort = $langs->transnoentitiesnoconv(
"ToAcceptRefuse");
3600 if ($mode ==
'signed') {
3601 $delay_warning =
$conf->propal->facturation->warning_delay;
3603 $label = $langs->trans(
"PropalsToBill");
3604 $labelShort = $langs->trans(
"ToBill");
3608 $response->warning_delay = $delay_warning / 60 / 60 / 24;
3609 $response->label = $label;
3610 $response->labelShort = $labelShort;
3611 $response->url = DOL_URL_ROOT.
'/comm/propal/list.php?search_status='.$status.
'&mainmenu=commercial&leftmenu=propals';
3612 $response->url_late = DOL_URL_ROOT.
'/comm/propal/list.php?search_option=late&mainmenu=commercial&leftmenu=propals&sortfield=p.datep&sortorder=asc';
3616 while ($obj = $this->db->fetch_object($resql)) {
3617 $response->nbtodo++;
3618 $response->total += $obj->total_ht;
3620 if ($mode ==
'opened') {
3621 $datelimit = $this->db->jdate($obj->datefin);
3622 if ($datelimit < ($now - $delay_warning)) {
3623 $response->nbtodolate++;
3632 $this->error = $this->db->error();
3647 global
$conf, $langs;
3652 $sql =
"SELECT rowid";
3653 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3654 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3655 $sql .= $this->db->plimit(100);
3657 $resql = $this->db->query($sql);
3659 $num_prods = $this->db->num_rows($resql);
3661 while ($i < $num_prods) {
3663 $row = $this->db->fetch_row($resql);
3664 $prodids[$i] = $row[0];
3670 $this->
ref =
'SPECIMEN';
3671 $this->ref_client =
'NEMICEPS';
3672 $this->specimen = 1;
3674 $this->date = time();
3675 $this->fin_validite = $this->date + 3600 * 24 * 30;
3676 $this->cond_reglement_id = 1;
3677 $this->cond_reglement_code =
'RECEP';
3678 $this->mode_reglement_id = 7;
3679 $this->mode_reglement_code =
'CHQ';
3680 $this->availability_id = 1;
3681 $this->availability_code =
'AV_NOW';
3682 $this->demand_reason_id = 1;
3683 $this->demand_reason_code =
'SRC_00';
3684 $this->note_public =
'This is a comment (public)';
3685 $this->note_private =
'This is a comment (private)';
3687 $this->multicurrency_tx = 1;
3688 $this->multicurrency_code =
$conf->currency;
3693 while ($xnbp < $nbp) {
3695 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3697 $line->subprice = 100;
3700 $line->localtax1_tx = 0;
3701 $line->localtax2_tx = 0;
3703 $line->total_ht = 50;
3704 $line->total_ttc = 60;
3705 $line->total_tva = 10;
3706 $line->remise_percent = 50;
3708 $line->total_ht = 100;
3709 $line->total_ttc = 120;
3710 $line->total_tva = 20;
3711 $line->remise_percent = 00;
3714 if ($num_prods > 0) {
3715 $prodid = mt_rand(1, $num_prods);
3716 $line->fk_product = $prodids[$prodid];
3717 $line->product_ref =
'SPECIMEN';
3720 $this->lines[$xnbp] = $line;
3722 $this->total_ht += $line->total_ht;
3723 $this->total_tva += $line->total_tva;
3724 $this->total_ttc += $line->total_ttc;
3741 $this->nb = array();
3743 $sql =
"SELECT count(p.rowid) as nb";
3744 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
3745 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3746 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3750 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3751 $search_sale = $user->id;
3754 if ($search_sale && $search_sale !=
'-1') {
3755 if ($search_sale == -2) {
3756 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3757 } elseif ($search_sale > 0) {
3758 $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).
")";
3762 $resql = $this->db->query($sql);
3765 while ($obj = $this->db->fetch_object($resql)) {
3766 $this->nb[
"proposals"] = $obj->nb;
3768 $this->db->free($resql);
3772 $this->error = $this->db->error();
3787 global
$conf, $langs;
3788 $langs->load(
"propal");
3792 if (!empty($classname)) {
3795 $file = $classname.
".php";
3798 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3799 foreach ($dirmodels as $reldir) {
3803 $mybool = ((bool) @include_once $dir.$file) || $mybool;
3811 $obj =
new $classname();
3812 '@phan-var-force ModeleNumRefPropales $obj';
3814 $numref = $obj->getNextValue($soc, $this);
3816 if ($numref !=
"") {
3819 $this->error = $obj->error;
3824 $langs->load(
"errors");
3825 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Proposal"));
3838 global
$conf, $langs, $user;
3840 $langs->load(
'propal');
3842 $nofetch = !empty($params[
'nofetch']);
3845 return [
'optimize' => $langs->trans(
"Proposal")];
3847 if ($user->hasRight(
'propal',
'lire')) {
3848 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly').
'<u>'.$langs->trans(
"Proposal").
'</u>';
3849 if (isset($this->
status)) {
3850 $datas[
'status'] =
' '.$this->getLibStatut(5);
3852 if (!empty($this->
ref)) {
3853 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3856 $langs->load(
'companies');
3857 if (empty($this->thirdparty)) {
3860 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
3862 if (!empty($this->ref_customer)) {
3863 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$this->ref_customer;
3866 $langs->load(
'project');
3867 if (is_null($this->project) || (is_object($this->project) && $this->project->isEmpty())) {
3869 if ($res > 0 && $this->project instanceof
Project) {
3870 $datas[
'project'] =
'<br><b>'.$langs->trans(
'Project').
':</b> '.$this->project->getNomUrl(1,
'', 0,
'1');
3874 if (!empty($this->total_ht)) {
3875 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
3877 if (!empty($this->total_tva)) {
3878 $datas[
'vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
3880 if (!empty($this->total_ttc)) {
3881 $datas[
'amountttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
3883 if (!empty($this->date)) {
3884 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
3886 if (!empty($this->date_signature)) {
3887 $datas[
'datesignature'] =
'<br><b>'.$langs->trans(
'DateSigning').
':</b> '.
dol_print_date($this->date_signature,
'day');
3889 if (!empty($this->delivery_date)) {
3890 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3908 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1)
3910 global $langs,
$conf, $user, $hookmanager;
3912 if (!empty(
$conf->dol_no_mouse_hover)) {
3919 'objecttype' => $this->element,
3920 'option' => $option,
3923 $classfortooltip =
'classfortooltip';
3926 $classfortooltip =
'classforajaxtooltip';
3927 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3934 if ($user->hasRight(
'propal',
'lire')) {
3935 if ($option ==
'') {
3936 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3937 } elseif ($option ==
'compta') {
3938 $url = DOL_URL_ROOT.
'/comm/propal/card.php?id='.$this->
id.$get_params;
3939 } elseif ($option ==
'expedition') {
3940 $url = DOL_URL_ROOT.
'/expedition/propal.php?id='.$this->
id.$get_params;
3941 } elseif ($option ==
'document') {
3942 $url = DOL_URL_ROOT.
'/comm/propal/document.php?id='.$this->
id.$get_params;
3945 if ($option !=
'nolink') {
3947 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3948 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3949 $add_save_lastsearch_values = 1;
3951 if ($add_save_lastsearch_values) {
3952 $url .=
'&save_lastsearch_values=1';
3958 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
3960 $label = $langs->trans(
"Proposal");
3961 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3963 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3964 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
3967 $linkstart =
'<a href="'.$url.
'"';
3968 $linkstart .= $linkclose.
'>';
3971 $result .= $linkstart;
3973 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
3975 if ($withpicto != 2) {
3976 $result .= $this->ref;
3978 $result .= $linkend;
3980 if ($addlinktonotes >= 0) {
3983 if ($addlinktonotes == 0) {
3984 if (!empty($this->note_private) || !empty($this->note_public)) {
3985 $txttoshow = $langs->trans(
'ViewPrivateNote');
3987 } elseif ($addlinktonotes == 1) {
3988 if (!empty($this->note_private)) {
3991 } elseif ($addlinktonotes == 2) {
3992 if (!empty($this->note_public)) {
3995 } elseif ($addlinktonotes == 3) {
3996 if ($user->socid > 0) {
3997 if (!empty($this->note_public)) {
4001 if (!empty($this->note_public)) {
4004 if (!empty($this->note_private)) {
4005 if (!empty($txttoshow)) {
4006 $txttoshow .=
'<br><br>';
4014 $result .=
' <span class="note inline-block">';
4015 $result .=
'<a href="'.DOL_URL_ROOT.
'/comm/propal/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($txttoshow).
'">';
4018 $result .=
'</span>';
4023 $hookmanager->initHooks(array($this->element .
'dao'));
4024 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
4025 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
4027 $result = $hookmanager->resPrint;
4029 $result .= $hookmanager->resPrint;
4042 return $this->
fetch_lines(0, 0, $sqlforgedfilters);
4056 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4058 $outputlangs->loadLangs(array(
"propale",
"products"));
4063 if ($this->model_pdf) {
4064 $modele = $this->model_pdf;
4070 $modelpath =
"core/modules/propale/doc/";
4072 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4120 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
4122 $return =
'<div class="box-flex-item box-flex-grow-zero">';
4123 $return .=
'<div class="info-box info-box-sm">';
4124 $return .=
'<div class="info-box-icon bg-infobox-action">';
4126 $return .=
'</div>';
4127 $return .=
'<div class="info-box-content">';
4128 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
4129 if ($selected >= 0) {
4130 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
4132 if (!empty($arraydata[
'projectlink'])) {
4133 $return .=
'<span class="info-box-ref"> | '.$arraydata[
'projectlink'].
'</span>';
4136 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
4137 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
4139 if (property_exists($this,
'total_ht')) {
4140 $return .=
'<span class="info-box-label amount" title="'.$langs->trans(
"AmountHT").
'">'.
price($this->total_ht).
'</span>';
4142 if (!empty($arraydata[
'authorlink'])) {
4143 $return .=
' <span class="info-box-label">'.$arraydata[
'authorlink'].
'</span>';
4145 if (method_exists($this,
'getLibStatut')) {
4146 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
4148 $return .=
'</div>';
4149 $return .=
'</div>';
4150 $return .=
'</div>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetchProject()
Load the project with id $this->fk_project into this->project.
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)
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.
Class to manage absolute discounts.
Class to manage Dolibarr database access.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
File of class to manage predefined price products or services by customer.
Class to manage predefined suppliers products.
Class to manage products or services.
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 clickable link of object (with eventually picto)
getKanbanView($option='', $arraydata=null)
Return clickable 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.
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...
closeProposal($user, $status, $note_private='', $notrigger=0, $note_public='')
Close/set the commercial proposal to status signed or refused (fill also date signature)
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)
Add a discount line into an proposal (as a proposal line) using an existing absolute discount (Consum...
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.
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.
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.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.