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';
68 public $element =
'propal';
73 public $table_element =
'propal';
78 public $table_element_line =
'propaldet';
83 public $fk_element =
'fk_propal';
88 public $picto =
'propal';
94 public $TRIGGER_PREFIX =
'PROPAL';
100 public $restrictiononfksoc = 1;
131 public $ref_customer;
165 public $date_validation;
170 public $date_signature;
175 public $user_signature;
192 public $delivery_date;
198 public $fin_validite;
203 public $user_author_id;
234 public $cond_reglement_code;
239 public $cond_reglement;
244 public $cond_reglement_doc;
249 public $cond_reglement_label;
254 public $mode_reglement_code;
259 public $mode_reglement;
266 public $deposit_percent;
278 public $address_type;
289 public $availability_id;
296 public $fk_availability;
301 public $availability_code;
306 public $availability;
311 public $duree_validite;
316 public $demand_reason_id;
321 public $demand_reason_code;
326 public $demand_reason;
331 public $warehouse_id;
336 public $lines = array();
343 public $labelStatus = array();
344 public $labelStatusShort = array();
375 public $fields = array(
376 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
377 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
378 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 20),
379 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 22),
380 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 40),
381 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'position' => 23),
382 '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),
383 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
384 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
385 'datep' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => -1,
'position' => 60),
386 'fin_validite' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' => 1,
'visible' => -1,
'position' => 65),
387 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 70),
388 'date_cloture' => array(
'type' =>
'datetime',
'label' =>
'DateClosing',
'enabled' => 1,
'visible' => -1,
'position' => 75),
389 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 80),
390 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 85),
391 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 90),
392 'fk_user_cloture' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserClosing',
'enabled' => 1,
'visible' => -1,
'position' => 95),
393 'price' => array(
'type' =>
'double',
'label' =>
'Price',
'enabled' => 1,
'visible' => -1,
'position' => 105),
394 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 125,
'isameasure' => 1),
395 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'VAT',
'enabled' => 1,
'visible' => -1,
'position' => 130,
'isameasure' => 1),
396 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax1',
'enabled' => 1,
'visible' => -1,
'position' => 135,
'isameasure' => 1),
397 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax2',
'enabled' => 1,
'visible' => -1,
'position' => 140,
'isameasure' => 1),
398 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 145,
'isameasure' => 1),
399 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 150),
400 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 155),
401 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 160),
402 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 161),
403 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 165),
404 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 170),
405 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 175),
406 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 180),
407 'date_livraison' => array(
'type' =>
'date',
'label' =>
'DateDeliveryPlanned',
'enabled' => 1,
'visible' => -1,
'position' => 185),
408 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMethod',
'enabled' => 1,
'visible' => -1,
'position' => 190),
409 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Fk warehouse',
'enabled' =>
'isModEnabled("stock")',
'visible' => -1,
'position' => 191),
410 'fk_availability' => array(
'type' =>
'integer',
'label' =>
'Availability',
'enabled' => 1,
'visible' => -1,
'position' => 195),
411 'fk_delivery_address' => array(
'type' =>
'integer',
'label' =>
'DeliveryAddress',
'enabled' => 1,
'visible' => 0,
'position' => 200),
412 'fk_input_reason' => array(
'type' =>
'integer',
'label' =>
'InputReason',
'enabled' => 1,
'visible' => -1,
'position' => 205),
413 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 215),
414 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 220),
415 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLabel',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 225),
416 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'MulticurrencyID',
'enabled' => 1,
'visible' => -1,
'position' => 230),
417 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCurrency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
418 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240,
'isameasure' => 1),
419 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 245,
'isameasure' => 1),
420 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 250,
'isameasure' => 1),
421 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 255,
'isameasure' => 1),
422 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 260),
423 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
424 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
465 $this->ismultientitymanaged = 1;
466 $this->socid = $socid;
467 $this->
id = $propalid;
471 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
487 public function add_product($idproduct, $qty, $remise_percent = 0)
496 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
497 if ($idproduct > 0) {
499 $prod->fetch($idproduct);
501 $productdesc =
$prod->description;
505 if (empty($tva_tx)) {
515 $price =
$prod->multiprices[$this->thirdparty->price_level];
517 $price =
$prod->price;
522 $line->fk_product = $idproduct;
523 $line->desc = $productdesc;
525 $line->subprice = $price;
526 $line->remise_percent = $remise_percent;
527 $line->vat_src_code = $vat_src_code;
528 $line->tva_tx = $tva_tx;
529 $line->fk_unit =
$prod->fk_unit;
531 $line->info_bits = 1;
534 $this->lines[] = $line;
552 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
553 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
558 $result = $remise->fetch($idremise);
561 if ($remise->fk_facture) {
562 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
563 $this->db->rollback();
569 $line->context = $this->context;
571 $line->fk_propal = $this->id;
572 $line->fk_remise_except = $remise->id;
573 $line->desc = $remise->description;
574 $line->vat_src_code = $remise->vat_src_code;
575 $line->tva_tx = $remise->tva_tx;
576 $line->localtax1_tx = $remise->localtax1_tx;
577 $line->localtax1_type = $remise->localtax1_type;
578 $line->localtax2_tx = $remise->localtax1_tx;
579 $line->localtax2_type = $remise->localtax1_type;
580 $line->subprice = -(float) $remise->amount_ht;
581 $line->fk_product = 0;
583 $line->remise_percent = 0;
585 $line->info_bits = 2;
587 $line->total_ht = -(float) $remise->amount_ht;
588 $line->total_tva = -(float) $remise->amount_tva;
589 $line->total_ttc = -(float) $remise->amount_ttc;
590 $line->total_localtax1 = -(float) $remise->total_localtax1;
591 $line->total_localtax2 = -(float) $remise->total_localtax2;
593 $result = $line->insert();
600 $this->db->rollback();
605 $this->db->rollback();
609 $this->db->rollback();
659 $remise_percent = 0.0,
660 $price_base_type =
'HT',
672 $array_options = array(),
677 $fk_remise_except = 0,
678 $noupdateafterinsertline = 0
682 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);
684 if ($this->
status == self::STATUS_DRAFT) {
685 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
688 if (empty($remise_percent)) {
694 if (empty($info_bits)) {
700 if (empty($fk_parent_line) || $fk_parent_line < 0) {
704 $remise_percent =
price2num($remise_percent);
707 $pu_ht_devise =
price2num($pu_ht_devise);
709 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
715 if ($price_base_type ==
'HT') {
727 $langs->load(
"errors");
728 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
734 $product_type = $type;
735 if (!empty($fk_product) && $fk_product > 0) {
736 $product =
new Product($this->db);
737 $result = $product->fetch($fk_product);
738 $product_type = $product->type;
740 if ($product->isStockManaged() && $product->stock_reel < $qty &&
getDolGlobalString(
'STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL')) {
741 $langs->load(
"errors");
742 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref);
743 $this->db->rollback();
755 $tmpproduct =
new Product($this->db);
756 $result = $tmpproduct->fetch($fk_product);
758 if ($newqty != $qty) {
760 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
767 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
768 $vat_src_code = $reg[1];
769 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
772 $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);
774 $total_ht = $tabprice[0];
775 $total_tva = $tabprice[1];
776 $total_ttc = $tabprice[2];
777 $total_localtax1 = $tabprice[9];
778 $total_localtax2 = $tabprice[10];
779 $pu_ht = $tabprice[3];
780 $pu_tva = $tabprice[4];
781 $pu_ttc = $tabprice[5];
784 $multicurrency_total_ht = $tabprice[16];
785 $multicurrency_total_tva = $tabprice[17];
786 $multicurrency_total_ttc = $tabprice[18];
787 $pu_ht_devise = $tabprice[19];
791 if (empty($ranktouse) || $ranktouse == -1) {
792 $rangmax = $this->
line_max($fk_parent_line);
793 $ranktouse = $rangmax + 1;
799 $this->line->context = $this->context;
801 $this->line->fk_propal = $this->id;
802 $this->line->label = $label;
803 $this->line->desc = $desc;
804 $this->line->qty = (float) $qty;
806 $this->line->vat_src_code = $vat_src_code;
807 $this->line->tva_tx = $txtva;
808 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
809 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
810 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
811 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
812 $this->line->fk_product = $fk_product;
813 $this->line->product_type = $type;
814 $this->line->fk_remise_except = $fk_remise_except;
815 $this->line->remise_percent = $remise_percent;
816 $this->line->subprice = (float) $pu_ht;
818 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
819 $this->line->rang = $ranktouse;
820 $this->line->info_bits = $info_bits;
821 $this->line->total_ht = (float) $total_ht;
822 $this->line->total_tva = (float) $total_tva;
823 $this->line->total_localtax1 = (float) $total_localtax1;
824 $this->line->total_localtax2 = (float) $total_localtax2;
825 $this->line->total_ttc = (float) $total_ttc;
826 $this->line->special_code = $special_code;
827 $this->line->fk_parent_line = $fk_parent_line;
828 $this->line->fk_unit = $fk_unit;
831 $this->line->date_end = $date_end;
833 $this->line->fk_fournprice = $fk_fournprice;
834 $this->line->pa_ht = $pa_ht;
836 $this->line->origin_id = $origin_id;
837 $this->line->origin = $origin;
840 $this->line->fk_multicurrency = $this->fk_multicurrency;
841 $this->line->multicurrency_code = $this->multicurrency_code;
842 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
843 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
844 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
845 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
848 if (empty($qty) && empty($special_code)) {
849 $this->line->special_code = 3;
852 if (is_array($array_options) && count($array_options) > 0) {
853 $this->line->array_options = $array_options;
856 $result = $this->line->insert();
858 if (!isset($this->context[
'createfromclone'])) {
859 if (!empty($fk_parent_line)) {
862 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
864 foreach ($this->lines as $tmpline) {
865 if ($tmpline->rang >= $ranktouse) {
866 if (!empty($tmpline->id)) {
873 $this->lines[] = $this->line;
876 foreach ($this->lines as $tmpline) {
877 if ($tmpline->id == $origin_id && $tmpline->element == $origin) {
878 $this->line->extraparams = $tmpline->extraparams;
879 $this->line->setExtraParameters();
885 if (empty($noupdateafterinsertline)) {
891 return $this->line->id;
893 $this->error = $this->db->error();
894 $this->db->rollback();
899 $this->db->rollback();
903 dol_syslog(get_class($this).
"::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR);
938 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)
943 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
947 dol_syslog(get_class($this).
"::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent,
948 txtva=$txtva, desc=".
dol_trunc($desc, 16).
", 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) {
973 $langs->load(
"errors");
974 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
978 if ($this->
status == self::STATUS_DRAFT) {
990 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
991 $vat_src_code = $reg[1];
992 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1001 if ($tmpline->fetch($rowid) > 0) {
1003 if ($newqty != $qty) {
1005 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
1010 $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);
1011 $total_ht = $tabprice[0];
1012 $total_tva = $tabprice[1];
1013 $total_ttc = $tabprice[2];
1014 $total_localtax1 = $tabprice[9];
1015 $total_localtax2 = $tabprice[10];
1016 $pu_ht = $tabprice[3];
1017 $pu_tva = $tabprice[4];
1018 $pu_ttc = $tabprice[5];
1021 $multicurrency_total_ht = $tabprice[16];
1022 $multicurrency_total_tva = $tabprice[17];
1023 $multicurrency_total_ttc = $tabprice[18];
1024 $pu_ht_devise = $tabprice[19];
1028 $line->fetch($rowid);
1030 $staticline = clone $line;
1032 $line->oldline = $staticline;
1033 $this->line = $line;
1034 $this->line->context = $this->context;
1035 $this->line->rang = $rang;
1038 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
1039 $rangmax = $this->
line_max($fk_parent_line);
1040 $this->line->rang = $rangmax + 1;
1044 $this->line->id = $rowid;
1045 $this->line->label = $label;
1046 $this->line->desc = $desc;
1047 $this->line->qty = $qty;
1048 $this->line->product_type = $type;
1049 $this->line->vat_src_code = $vat_src_code;
1050 $this->line->tva_tx = $txtva;
1051 $this->line->localtax1_tx = $txlocaltax1;
1052 $this->line->localtax2_tx = $txlocaltax2;
1053 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
1054 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
1055 $this->line->remise_percent = $remise_percent;
1056 $this->line->subprice = (float) $pu_ht;
1058 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
1059 $this->line->info_bits = $info_bits;
1061 $this->line->total_ht = (float) $total_ht;
1062 $this->line->total_tva = (float) $total_tva;
1063 $this->line->total_localtax1 = (float) $total_localtax1;
1064 $this->line->total_localtax2 = (float) $total_localtax2;
1065 $this->line->total_ttc = (float) $total_ttc;
1066 $this->line->special_code = $special_code;
1067 $this->line->fk_parent_line = $fk_parent_line;
1068 $this->line->skip_update_total = $skip_update_total;
1069 $this->line->fk_unit = $fk_unit;
1071 $this->line->fk_fournprice = $fk_fournprice;
1072 $this->line->pa_ht = $pa_ht;
1075 $this->line->date_end = $date_end;
1077 if (is_array($array_options) && count($array_options) > 0) {
1079 foreach ($array_options as $key => $value) {
1080 $this->line->array_options[$key] = $array_options[$key];
1085 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
1086 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
1087 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
1088 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
1090 $result = $this->line->update($notrigger);
1093 if (!empty($fk_parent_line)) {
1103 $this->db->commit();
1107 $this->db->rollback();
1111 dol_syslog(get_class($this).
"::updateline Erreur -2 Propal en mode incompatible pour cette action");
1128 if ($this->
status == self::STATUS_DRAFT) {
1133 $line->context = $this->context;
1136 $line->fetch($lineid);
1141 if ($id > 0 && (
int) $line->fk_propal !== (
int) $id) {
1142 $this->db->rollback();
1143 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1148 $staticline = clone $line;
1149 $line->oldline = $staticline;
1151 if ($line->delete($user) > 0) {
1154 $this->db->commit();
1158 $this->db->rollback();
1162 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1176 public function create($user, $notrigger = 0)
1185 if (empty($this->
date)) {
1186 $this->
date = $this->datep;
1188 $this->fin_validite = $this->
date + ($this->duree_validite * 24 * 3600);
1189 if (empty($this->availability_id)) {
1190 $this->availability_id = 0;
1192 if (empty($this->demand_reason_id)) {
1193 $this->demand_reason_id = 0;
1197 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1202 if (empty($this->fk_multicurrency)) {
1204 $this->fk_multicurrency = 0;
1205 $this->multicurrency_tx = 1;
1211 $delivery_date = $this->delivery_date;
1218 $this->error =
"Failed to fetch company";
1219 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1224 if (!empty($this->
ref)) {
1227 $this->error =
'ErrorRefAlreadyExists';
1228 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1229 $this->db->rollback();
1234 if (empty($this->
date)) {
1235 $this->error =
"Date of proposal is required";
1236 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1244 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
1247 $sql .=
", total_tva";
1248 $sql .=
", total_ttc";
1252 $sql .=
", fk_user_author";
1253 $sql .=
", note_private";
1254 $sql .=
", note_public";
1255 $sql .=
", model_pdf";
1256 $sql .=
", fin_validite";
1257 $sql .=
", fk_cond_reglement";
1258 $sql .=
", deposit_percent";
1259 $sql .=
", fk_mode_reglement";
1260 $sql .=
", fk_account";
1261 $sql .=
", ref_client";
1262 $sql .=
", ref_ext";
1263 $sql .=
", date_livraison";
1264 $sql .=
", fk_shipping_method";
1265 $sql .=
", fk_warehouse";
1266 $sql .=
", fk_availability";
1267 $sql .=
", fk_input_reason";
1268 $sql .=
", fk_projet";
1269 $sql .=
", fk_incoterms";
1270 $sql .=
", location_incoterms";
1272 $sql .=
", fk_multicurrency";
1273 $sql .=
", multicurrency_code";
1274 $sql .=
", multicurrency_tx";
1276 $sql .=
" VALUES (";
1277 $sql .= ((int) $this->socid);
1281 $sql .=
", '".$this->db->idate($this->
date).
"'";
1282 $sql .=
", '".$this->db->idate($now).
"'";
1283 $sql .=
", '(PROV)'";
1284 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
1285 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1286 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1287 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1288 $sql .=
", ".($this->fin_validite !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
"NULL");
1289 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1290 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
'NULL');
1291 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1292 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1293 $sql .=
", '".$this->db->escape((
string) $this->ref_client).
"'";
1294 $sql .=
", '".$this->db->escape((
string) $this->ref_ext).
"'";
1295 $sql .=
", ".(!
isDolTms($delivery_date) ?
"NULL" :
"'".$this->db->idate($delivery_date).
"'");
1296 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
'NULL');
1297 $sql .=
", ".($this->warehouse_id > 0 ? ((int) $this->warehouse_id) :
'NULL');
1298 $sql .=
", ".((int) $this->availability_id);
1299 $sql .=
", ".((int) $this->demand_reason_id);
1300 $sql .=
", ".($this->fk_project ? ((int) $this->fk_project) :
"null");
1301 $sql .=
", ".(int) $this->fk_incoterms;
1302 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1303 $sql .=
", ".(int) $this->entity;
1304 $sql .=
", ".(int) $this->fk_multicurrency;
1305 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1306 $sql .=
", ".(float) $this->multicurrency_tx;
1309 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1310 $resql = $this->db->query($sql);
1312 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
1315 $this->
ref =
'(PROV'.$this->id.
')';
1316 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1318 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1319 $resql = $this->db->query($sql);
1324 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1325 $this->linked_objects = $this->linkedObjectsIds;
1329 if (!$error && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1330 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1331 if (is_array($tmp_origin_id)) {
1332 foreach ($tmp_origin_id as $origin_id) {
1335 $this->error = $this->db->lasterror();
1340 $origin_id = $tmp_origin_id;
1343 $this->error = $this->db->lasterror();
1354 $fk_parent_line = 0;
1355 $num = count($this->lines);
1358 for ($i = 0; $i < $num; $i++) {
1359 if (!is_object($this->lines[$i])) {
1361 foreach ($this->lines[$i] as $key => $val) {
1362 $lineobj->$key = $val;
1364 $this->lines[$i] = $lineobj;
1368 for ($i = 0; $i < $num; $i++) {
1369 $line = $this->lines[$i];
1372 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1373 $fk_parent_line = 0;
1376 $vatrate = $line->tva_tx;
1377 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', $vatrate)) {
1378 $vatrate .=
' ('.$line->vat_src_code.
')';
1382 $originid = $line->origin_id;
1383 $origintype = empty($line->origin_type) ? $line->origin : $line->origin_type;
1385 $originid = $line->id;
1386 $origintype = $this->element;
1394 $line->localtax1_tx,
1395 $line->localtax2_tx,
1397 $line->remise_percent,
1401 $line->product_type,
1403 $line->special_code,
1405 $line->fk_fournprice,
1410 $line->array_options,
1412 (
string) $origintype,
1421 $this->error = $this->db->error;
1427 $line->id = $result;
1431 if ($result > 0 && !empty($line->extraparams)) {
1433 $newline->id = $result;
1434 $newline->extraparams = $line->extraparams;
1435 $newline->setExtraParameters();
1439 if ($result > 0 && $line->product_type == 9) {
1440 $fk_parent_line = $result;
1455 if (!$error && !$notrigger) {
1457 $result = $this->call_trigger(
'PROPAL_CREATE', $user);
1464 $this->error = $this->db->lasterror();
1469 $this->error = $this->db->lasterror();
1474 $this->db->commit();
1475 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1478 $this->db->rollback();
1482 $this->error = $this->db->lasterror();
1483 $this->db->rollback();
1498 public function createFromClone(
User $user, $socid = 0, $forceentity =
null, $update_prices =
false, $update_desc =
false)
1509 $object =
new self($this->db);
1516 $objsoc =
new Societe($this->db);
1519 if (!empty($socid) && $socid !=
$object->socid) {
1520 if ($objsoc->fetch($socid) > 0) {
1522 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1523 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
null);
1524 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1525 $object->fk_delivery_address = 0;
1548 $objsoc->fetch(
$object->socid);
1552 if ($update_prices ===
true || $update_desc ===
true) {
1553 if ($objsoc->id > 0 && !empty(
$object->lines)) {
1556 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1559 foreach (
$object->lines as $line) {
1562 if ($line->fk_product > 0) {
1564 $res =
$prod->fetch($line->fk_product);
1566 if ($update_prices ===
true) {
1567 $pu_ht =
$prod->price;
1569 $remise_percent = $objsoc->remise_percent;
1572 $pu_ht =
$prod->multiprices[$objsoc->price_level];
1574 if (isset(
$prod->multiprices_tva_tx[$objsoc->price_level])) {
1575 $tva_tx = (
string)
$prod->multiprices_tva_tx[$objsoc->price_level];
1580 $filter = array(
't.fk_product' => (
string)
$prod->id,
't.fk_soc' => (
string) $objsoc->id);
1581 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1584 if (count($prodcustprice->lines) > 0) {
1585 $date_now = (int) floor(
dol_now() / 86400) * 86400;
1586 foreach ($prodcustprice->lines as $k => $custprice_line) {
1587 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
1588 $pu_ht =
price($custprice_line->price);
1589 $tva_tx = ($custprice_line->default_vat_code ? $custprice_line->tva_tx .
' (' . $custprice_line->default_vat_code .
' )' : $custprice_line->tva_tx);
1590 if ($custprice_line->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1591 $tva_tx .=
' (' . $custprice_line->default_vat_code .
')';
1593 $remise_percent = $custprice_line->discount_percent;
1601 $line->subprice = $pu_ht;
1602 $line->tva_tx = $tva_tx;
1603 $line->remise_percent = $remise_percent;
1606 if ($line->fk_fournprice > 0) {
1607 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1609 if ($prodfourn->fetch_product_fournisseur_price($line->fk_fournprice) > 0) {
1610 $line->pa_ht =
price2num($prodfourn->fourn_unitprice * (1 - $prodfourn->fourn_remise_percent / 100),
'MU');
1612 $line->fk_fournprice = 0;
1616 if ($update_desc ===
true) {
1617 $line->desc =
$prod->description;
1627 $object->entity = (!empty($forceentity) ? $forceentity :
$object->entity);
1632 $object->user_creation_id = $user->id;
1633 $object->user_validation_id = 0;
1646 $object->context[
'createfromclone'] =
'createfromclone';
1647 $result =
$object->create($user);
1655 if (
$object->copy_linked_contact($this,
'internal') < 0) {
1662 if ($this->socid ==
$object->socid) {
1663 if (
$object->copy_linked_contact($this,
'external') < 0) {
1671 if (is_object($hookmanager)) {
1672 $parameters = array(
'objFrom' => $this,
'clonedObj' =>
$object);
1674 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1682 unset(
$object->context[
'createfromclone']);
1686 $this->db->commit();
1689 $this->db->rollback();
1703 public function fetch($rowid, $ref =
'', $ref_ext =
'', $forceentity = 0)
1705 $sql =
"SELECT p.rowid, p.ref, p.entity, p.fk_soc";
1706 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1707 $sql .=
", p.datec";
1708 $sql .=
", p.date_signature as dates";
1709 $sql .=
", p.date_valid as datev";
1710 $sql .=
", p.date_cloture";
1711 $sql .=
", p.datep as dp";
1712 $sql .=
", p.fin_validite as dfv";
1713 $sql .=
", p.date_livraison as delivery_date";
1714 $sql .=
", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
1715 $sql .=
", p.note_private, p.note_public";
1716 $sql .=
", p.fk_projet as fk_project, p.fk_statut";
1717 $sql .=
", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1718 $sql .=
", p.fk_delivery_address";
1719 $sql .=
", p.fk_availability";
1720 $sql .=
", p.fk_input_reason";
1721 $sql .=
", p.fk_cond_reglement";
1722 $sql .=
", p.fk_mode_reglement";
1723 $sql .=
', p.fk_account';
1724 $sql .=
", p.fk_shipping_method";
1725 $sql .=
", p.fk_warehouse";
1726 $sql .=
", p.fk_incoterms, p.location_incoterms";
1727 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1728 $sql .=
", p.tms as date_modification";
1729 $sql .=
", i.libelle as label_incoterms";
1730 $sql .=
", c.label as statut_label";
1731 $sql .=
", ca.code as availability_code, ca.label as availability";
1732 $sql .=
", dr.code as demand_reason_code, dr.label as demand_reason";
1733 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1734 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1735 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
1736 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_propalst as c ON p.fk_statut = c.id';
1737 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.
getEntity(
'c_paiement').
')';
1738 $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').
')';
1739 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON p.fk_availability = ca.rowid';
1740 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
1741 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON p.fk_incoterms = i.rowid';
1744 if (!empty($forceentity)) {
1745 $sql .=
" WHERE p.entity = ".(int) $forceentity;
1747 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
1749 $sql .=
" AND p.ref='".$this->db->escape($ref).
"'";
1752 $sql .=
" WHERE p.rowid = ".((int) $rowid);
1755 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1756 $resql = $this->db->query($sql);
1758 if ($this->db->num_rows($resql)) {
1759 $obj = $this->db->fetch_object($resql);
1761 $this->
id = $obj->rowid;
1762 $this->entity = $obj->entity;
1764 $this->
ref = $obj->ref;
1765 $this->ref_client = $obj->ref_client;
1766 $this->ref_customer = $obj->ref_client;
1767 $this->ref_ext = $obj->ref_ext;
1769 $this->total = $obj->total_ttc;
1770 $this->total_ttc = $obj->total_ttc;
1771 $this->total_ht = $obj->total_ht;
1772 $this->total_tva = $obj->total_tva;
1773 $this->total_localtax1 = $obj->localtax1;
1774 $this->total_localtax2 = $obj->localtax2;
1776 $this->socid = $obj->fk_soc;
1777 $this->thirdparty =
null;
1779 $this->fk_project = $obj->fk_project;
1780 $this->project =
null;
1782 $this->model_pdf = $obj->model_pdf;
1783 $this->last_main_doc = $obj->last_main_doc;
1784 $this->note = $obj->note_private;
1785 $this->note_private = $obj->note_private;
1786 $this->note_public = $obj->note_public;
1788 $this->
status = (int) $obj->fk_statut;
1789 $this->statut = $this->status;
1791 $this->datec = $this->db->jdate($obj->datec);
1792 $this->datev = $this->db->jdate($obj->datev);
1793 $this->date_creation = $this->db->jdate($obj->datec);
1794 $this->date_validation = $this->db->jdate($obj->datev);
1795 $this->date_modification = $this->db->jdate($obj->date_modification);
1796 $this->date_signature = $this->db->jdate($obj->dates);
1797 $this->date_cloture = $this->db->jdate($obj->date_cloture);
1798 $this->
date = $this->db->jdate($obj->dp);
1799 $this->datep = $this->db->jdate($obj->dp);
1800 $this->fin_validite = $this->db->jdate($obj->dfv);
1801 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1802 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1803 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
1804 $this->availability_id = $obj->fk_availability;
1805 $this->availability_code = $obj->availability_code;
1807 $this->demand_reason_id = $obj->fk_input_reason;
1808 $this->demand_reason_code = $obj->demand_reason_code;
1810 $this->fk_address = $obj->fk_delivery_address;
1812 $this->mode_reglement_id = $obj->fk_mode_reglement;
1813 $this->mode_reglement_code = $obj->mode_reglement_code;
1814 $this->mode_reglement = $obj->mode_reglement;
1815 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1816 $this->cond_reglement_id = $obj->fk_cond_reglement;
1817 $this->cond_reglement_code = $obj->cond_reglement_code;
1818 $this->cond_reglement = $obj->cond_reglement;
1819 $this->cond_reglement_label = $obj->cond_reglement;
1820 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1821 $this->deposit_percent = $obj->deposit_percent;
1823 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1825 $this->user_author_id = $obj->fk_user_author;
1826 $this->user_validation_id = $obj->fk_user_valid;
1827 $this->user_closing_id = $obj->fk_user_cloture;
1830 $this->fk_incoterms = $obj->fk_incoterms;
1831 $this->location_incoterms = $obj->location_incoterms;
1832 $this->label_incoterms = $obj->label_incoterms;
1835 $this->fk_multicurrency = $obj->fk_multicurrency;
1836 $this->multicurrency_code = $obj->multicurrency_code;
1837 $this->multicurrency_tx = $obj->multicurrency_tx;
1838 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1839 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1840 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1846 $this->db->free($resql);
1848 $this->lines = array();
1859 $this->error =
"Record Not Found";
1862 $this->error = $this->db->lasterror();
1879 if (isset($this->
ref)) {
1880 $this->
ref = trim($this->
ref);
1882 if (isset($this->ref_client)) {
1883 $this->ref_client = trim($this->ref_client);
1885 if (isset($this->note) || isset($this->note_private)) {
1886 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1888 if (isset($this->note_public)) {
1889 $this->note_public = trim($this->note_public);
1891 if (isset($this->model_pdf)) {
1892 $this->model_pdf = trim($this->model_pdf);
1894 if (isset($this->import_key)) {
1895 $this->import_key = trim($this->import_key);
1897 if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
1898 $this->fin_validite = $this->
date + ($this->duree_validite * 24 * 3600);
1905 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1906 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET";
1907 $sql .=
" ref = ".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1908 $sql .=
" ref_client = ".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
1909 $sql .=
" ref_ext = ".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1910 $sql .=
" fk_soc = ".(!empty($this->socid) ? (int) $this->socid :
"null").
",";
1911 $sql .=
" datep = ".(strval($this->
date) !=
'' ?
"'".$this->db->idate($this->
date).
"'" :
'null').
",";
1912 if (!empty($this->fin_validite)) {
1913 $sql .=
" fin_validite = ".(strval($this->fin_validite) !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
'null').
",";
1915 $sql .=
" date_valid = ".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1916 $sql .=
" total_tva = ".(isset($this->total_tva) ? (float) $this->total_tva :
"null").
",";
1917 $sql .=
" localtax1 = ".(isset($this->total_localtax1) ? (float) $this->total_localtax1 :
"null").
",";
1918 $sql .=
" localtax2 = ".(isset($this->total_localtax2) ? (float) $this->total_localtax2 :
"null").
",";
1919 $sql .=
" total_ht = ".(isset($this->total_ht) ? (float) $this->total_ht :
"null").
",";
1920 $sql .=
" total_ttc = ".(isset($this->total_ttc) ? (float) $this->total_ttc :
"null").
",";
1921 $sql .=
" fk_statut = ".(isset($this->
status) ? (int) $this->
status :
"null").
",";
1922 $sql .=
" fk_user_author = ".(!empty($this->user_author_id) ? (int) $this->user_author_id :
"null").
",";
1923 $sql .=
" fk_user_valid = ".(!empty($this->user_validation_id) ? (int) $this->user_validation_id :
"null").
",";
1925 $sql .=
" fk_projet = ".(!empty($this->fk_project) ? (int) $this->fk_project :
"null").
",";
1926 $sql .=
" fk_cond_reglement = ".(!empty($this->cond_reglement_id) ? (int) $this->cond_reglement_id :
"null").
",";
1927 $sql .=
" deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1928 $sql .=
" fk_mode_reglement = ".(!empty($this->mode_reglement_id) ? (int) $this->mode_reglement_id :
"null").
",";
1929 $sql .=
" fk_input_reason = ".(!empty($this->demand_reason_id) ? (int) $this->demand_reason_id :
"null").
",";
1930 $sql .=
" fk_shipping_method = ".(isset($this->shipping_method_id) ? (int) $this->shipping_method_id :
"null").
",";
1931 $sql .=
" fk_availability = ".(!empty($this->availability_id) ? (int) $this->availability_id :
"null").
",";
1932 $sql .=
" note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1933 $sql .=
" note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1934 $sql .=
" model_pdf = ".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1935 $sql .=
" import_key = ".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1936 $sql .=
" WHERE rowid = ".((int) $this->
id);
1940 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1941 $resql = $this->db->query($sql);
1944 $this->errors[] =
"Error ".$this->db->lasterror();
1954 if (!$error && !$notrigger) {
1956 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
1965 foreach ($this->errors as $errmsg) {
1966 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1967 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1969 $this->db->rollback();
1972 $this->db->commit();
1987 public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $sqlforgedfilters =
'')
1990 $this->lines = array();
1992 $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.subprice_ttc, d.fk_product,';
1993 $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,';
1994 $sql .=
' d.fk_unit,';
1995 $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,';
1996 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units,';
1997 $sql .=
' p.customcode, p.fk_country as country_id, c.code as country_code,';
1998 $sql .=
' d.date_start, d.date_end, d.extraparams,';
1999 $sql .=
' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc';
2000 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as d';
2001 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (d.fk_product = p.rowid)';
2002 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON c.rowid = p.fk_country';
2003 $sql .=
' WHERE d.fk_propal = '.((int) $this->
id);
2004 if ($only_product) {
2005 $sql .=
' AND p.fk_product_type = 0';
2007 if ($sqlforgedfilters) {
2008 $sql .= $sqlforgedfilters;
2010 $sql .=
' ORDER BY d.rang, d.rowid';
2012 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
2013 $result = $this->db->query($sql);
2015 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
2017 $num = $this->db->num_rows($result);
2021 $objp = $this->db->fetch_object($result);
2025 $line->rowid = $objp->rowid;
2026 $line->id = $objp->rowid;
2027 $line->fk_propal = $objp->fk_propal;
2028 $line->fk_parent_line = $objp->fk_parent_line;
2029 $line->label = $objp->custom_label;
2030 $line->desc = $objp->description;
2031 $line->description = $objp->description;
2032 $line->qty = $objp->qty;
2033 $line->vat_src_code = $objp->vat_src_code;
2034 $line->tva_tx = $objp->tva_tx;
2035 $line->localtax1_tx = $objp->localtax1_tx;
2036 $line->localtax2_tx = $objp->localtax2_tx;
2037 $line->localtax1_type = $objp->localtax1_type;
2038 $line->localtax2_type = $objp->localtax2_type;
2039 $line->subprice = $objp->subprice;
2040 $line->subprice_ttc = $objp->subprice_ttc;
2041 $line->fk_remise_except = $objp->fk_remise_except;
2042 $line->remise_percent = $objp->remise_percent;
2044 $line->info_bits = $objp->info_bits;
2045 $line->total_ht = $objp->total_ht;
2046 $line->total_tva = $objp->total_tva;
2047 $line->total_localtax1 = $objp->total_localtax1;
2048 $line->total_localtax2 = $objp->total_localtax2;
2049 $line->total_ttc = $objp->total_ttc;
2050 $line->fk_fournprice = $objp->fk_fournprice;
2051 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
2052 $line->pa_ht = $marginInfos[0];
2053 $line->marge_tx = $marginInfos[1];
2054 $line->marque_tx = $marginInfos[2];
2055 $line->special_code = $objp->special_code;
2056 $line->rang = $objp->rang;
2058 $line->fk_product = $objp->fk_product;
2060 $line->ref = $objp->product_ref;
2061 $line->libelle = $objp->product_label;
2063 $line->product_ref = $objp->product_ref;
2064 $line->product_label = $objp->product_label;
2065 $line->product_desc = $objp->product_desc;
2066 $line->product_tobatch = $objp->product_tobatch;
2067 $line->product_barcode = $objp->product_barcode;
2068 $line->product_custom_code = $objp->customcode;
2069 $line->product_custom_country_id = $objp->country_id;
2070 $line->product_custom_country_code = $objp->country_code;
2071 $line->product_type = $objp->product_type;
2072 $line->fk_product_type = $objp->fk_product_type;
2074 $line->fk_unit = $objp->fk_unit;
2075 $line->weight = $objp->weight;
2076 $line->weight_units = $objp->weight_units;
2077 $line->volume = $objp->volume;
2078 $line->volume_units = $objp->volume_units;
2080 $line->date_start = $this->db->jdate($objp->date_start);
2081 $line->date_end = $this->db->jdate($objp->date_end);
2083 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
2086 $line->fk_multicurrency = $objp->fk_multicurrency;
2087 $line->multicurrency_code = $objp->multicurrency_code;
2088 $line->multicurrency_subprice = $objp->multicurrency_subprice;
2089 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
2090 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
2091 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2093 $line->fetch_optionals();
2096 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
2097 $tmpproduct =
new Product($this->db);
2098 $tmpproduct->fetch($objp->fk_product);
2099 $tmpproduct->getMultiLangs();
2101 $line->multilangs = $tmpproduct->multilangs;
2104 $this->lines[$i] = $line;
2109 $this->db->free($result);
2113 $this->error = $this->db->lasterror();
2125 public function valid($user, $notrigger = 0)
2129 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2134 if ($this->
status == self::STATUS_VALIDATED) {
2135 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
2139 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'creer'))
2140 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'propal_advance',
'validate')))) {
2141 $this->error =
'ErrorPermissionDenied';
2142 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
2147 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
2156 $soc =
new Societe($this->db);
2157 $soc->fetch($this->socid);
2160 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
2161 $num = $this->getNextNumRef($soc);
2167 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2168 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
2169 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
", date_valid='".$this->db->idate($now).
"', fk_user_valid=".((int) $user->id);
2172 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
2173 $resql = $this->db->query($sql);
2180 if (!$error && !$notrigger) {
2182 $result = $this->call_trigger(
'PROPAL_VALIDATE', $user);
2190 $this->oldref = $this->ref;
2193 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
2195 $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).
"'";
2196 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
2197 $resql = $this->db->query($sql);
2200 $this->error = $this->db->lasterror();
2202 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'propale/".$this->db->escape($this->newref).
"'";
2203 $sql .=
" WHERE filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
2204 $resql = $this->db->query($sql);
2207 $this->error = $this->db->lasterror();
2213 $dirsource =
$conf->propal->multidir_output[$this->entity].
'/'.$oldref;
2214 $dirdest =
$conf->propal->multidir_output[$this->entity].
'/'.$newref;
2215 if (!$error && file_exists($dirsource)) {
2216 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
2217 if (@rename($dirsource, $dirdest)) {
2220 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
2221 foreach ($listoffiles as $fileentry) {
2222 $dirsource = $fileentry[
'name'];
2223 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
2224 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
2225 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
2226 @rename($dirsource, $dirdest);
2235 $this->user_validation_id = $user->id;
2236 $this->datev = $now;
2237 $this->date_validation = $now;
2239 $this->db->commit();
2242 $this->db->rollback();
2261 $this->error =
'ErrorBadParameter';
2262 dol_syslog(get_class($this).
"::set_date ".$this->error, LOG_ERR);
2266 if ($user->hasRight(
'propal',
'creer')) {
2271 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2272 $sql .=
" SET datep = '".$this->db->idate($date).
"'";
2273 $sql .=
" WHERE rowid = ".((int) $this->
id);
2276 $resql = $this->db->query($sql);
2278 $this->errors[] = $this->db->error();
2283 $this->oldcopy = clone $this;
2284 $this->
date = $date;
2285 $this->datep = $date;
2288 if (!$notrigger && empty($error)) {
2290 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2298 $this->db->commit();
2301 foreach ($this->errors as $errmsg) {
2302 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2303 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2305 $this->db->rollback();
2325 if ($user->hasRight(
'propal',
'creer')) {
2330 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2331 $sql .=
" SET fin_validite = ".($date_end_validity !=
'' ?
"'".$this->db->idate($date_end_validity).
"'" :
'null');
2332 $sql .=
" WHERE rowid = ".((int) $this->
id);
2336 $resql = $this->db->query($sql);
2338 $this->errors[] = $this->db->error();
2344 $this->oldcopy = clone $this;
2345 $this->fin_validite = $date_end_validity;
2348 if (!$notrigger && empty($error)) {
2350 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2358 $this->db->commit();
2361 foreach ($this->errors as $errmsg) {
2362 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2363 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2365 $this->db->rollback();
2399 if ($user->hasRight(
'propal',
'creer')) {
2404 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2405 $sql .=
" SET date_livraison = ".(isDolTms($delivery_date) ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2406 $sql .=
" WHERE rowid = ".((int) $this->
id);
2409 $resql = $this->db->query($sql);
2411 $this->errors[] = $this->db->error();
2416 $this->oldcopy = clone $this;
2417 $this->delivery_date = $delivery_date;
2420 if (!$notrigger && empty($error)) {
2422 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2430 $this->db->commit();
2433 foreach ($this->errors as $errmsg) {
2434 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2435 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2437 $this->db->rollback();
2457 if ($this->
status >= self::STATUS_DRAFT) {
2462 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2463 $sql .=
" SET fk_availability = ".((int) ($id > 0 ? ((
int) $id) : 0));
2464 $sql .=
" WHERE rowid = ".((int) $this->
id);
2467 $resql = $this->db->query($sql);
2469 $this->errors[] = $this->db->error();
2474 $this->oldcopy = clone $this;
2475 $this->fk_availability =
$id;
2476 $this->availability_id =
$id;
2479 if (!$notrigger && empty($error)) {
2481 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2489 $this->db->commit();
2492 foreach ($this->errors as $errmsg) {
2493 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2494 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2496 $this->db->rollback();
2500 $error_str =
'Propal status do not meet requirement '.$this->status;
2502 $this->error = $error_str;
2503 $this->errors[] = $this->error;
2520 if ($user->hasRight(
'propal',
'creer') && $this->status >= self::STATUS_DRAFT) {
2525 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2526 $sql .=
" SET fk_input_reason = ".((int) $id);
2527 $sql .=
" WHERE rowid = ".((int) $this->
id);
2530 $resql = $this->db->query($sql);
2532 $this->errors[] = $this->db->error();
2538 $this->oldcopy = clone $this;
2540 $this->demand_reason_id = $id;
2544 if (!$notrigger && empty($error)) {
2546 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2554 $this->db->commit();
2557 foreach ($this->errors as $errmsg) {
2558 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2559 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2561 $this->db->rollback();
2565 $error_str =
'Propal status do not meet requirement '.$this->status;
2567 $this->error = $error_str;
2568 $this->errors[] = $this->error;
2585 if ($user->hasRight(
'propal',
'creer')) {
2590 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2591 $sql .=
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
2592 $sql .=
" WHERE rowid = ".((int) $this->
id);
2594 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
2595 $resql = $this->db->query($sql);
2597 $this->errors[] = $this->db->error();
2602 $this->oldcopy = clone $this;
2603 $this->ref_customer = $ref_client;
2604 $this->ref_client = $ref_client;
2607 if (!$notrigger && empty($error)) {
2609 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2617 $this->db->commit();
2620 foreach ($this->errors as $errmsg) {
2621 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2622 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2624 $this->db->rollback();
2642 public function reopen($user, $status, $note =
'', $notrigger = 0)
2646 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2647 $sql .=
" SET fk_statut = ".((int) $status).
",";
2648 if (!empty($note)) {
2649 $sql .=
" note_private = '".$this->db->escape($note).
"',";
2651 $sql .=
" date_cloture=NULL, fk_user_cloture=NULL";
2652 $sql .=
" WHERE rowid = ".((int) $this->
id);
2656 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
2657 $resql = $this->db->query($sql);
2660 $this->errors[] =
"Error ".$this->db->lasterror();
2665 $result = $this->call_trigger(
'PROPAL_REOPEN', $user);
2675 if (!empty($this->errors)) {
2676 foreach ($this->errors as $errmsg) {
2677 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2678 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2681 $this->db->rollback();
2684 $this->statut = $status;
2687 $this->db->commit();
2702 public function closeProposal($user, $status, $note_private =
'', $notrigger = 0, $note_public =
'')
2704 global $langs,
$conf;
2711 $newprivatenote =
dol_concatdesc($this->note_private, $note_private);
2712 $newpublicnote =
dol_concatdesc($this->note_public, $note_public);
2715 $date_signature = $now;
2716 $fk_user_signature = $user->id;
2718 $this->
info($this->
id);
2719 if (!isset($this->date_signature) || $this->date_signature ==
'') {
2720 $date_signature = $now;
2721 $fk_user_signature = $user->id;
2723 $date_signature = $this->date_signature;
2724 $fk_user_signature = $this->user_signature->id;
2728 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2729 $sql .=
" SET fk_statut = ".((int) $status).
", note_private = '".$this->db->escape($newprivatenote).
"', note_public = '".$this->db->escape($newpublicnote).
"'";
2730 if ($status == self::STATUS_SIGNED) {
2731 $sql .=
", date_signature='".$this->db->idate($now).
"', fk_user_signature = ".((int) $fk_user_signature);
2733 $sql .=
" WHERE rowid = ".((int) $this->
id);
2735 $resql = $this->db->query($sql);
2739 $triggerName =
'PROPAL_CLOSE_REFUSED';
2741 if ($status == self::STATUS_SIGNED) {
2742 $triggerName =
'PROPAL_CLOSE_SIGNED';
2746 $soc =
new Societe($this->db);
2747 $soc->fetch($this->socid);
2748 $result = $soc->setAsCustomer();
2751 $this->error = $this->db->lasterror();
2752 $this->db->rollback();
2759 $outputlangs = $langs;
2762 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2763 $outputlangs->setDefaultLang($newlang);
2772 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2775 $this->oldcopy = clone $this;
2776 $this->statut = $status;
2778 $this->date_signature = $date_signature;
2779 $this->note_private = $newprivatenote;
2781 if (!$notrigger && empty($error)) {
2783 $result = $this->call_trigger($triggerName, $user);
2791 $this->db->commit();
2794 foreach ($this->errors as $errmsg) {
2795 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2796 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2798 if (!empty($this->oldcopy)) {
2799 $this->statut = $this->oldcopy->status;
2800 $this->
status = $this->oldcopy->status;
2801 $this->date_signature = $this->oldcopy->date_signature;
2802 $this->note_private = $this->oldcopy->note_private;
2805 $this->db->rollback();
2809 $this->error = $this->db->lasterror();
2810 $this->db->rollback();
2825 global
$conf, $langs;
2832 $triggerName =
'PROPAL_CLASSIFY_BILLED';
2838 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2839 $sql .=
" SET fk_statut = ".self::STATUS_BILLED.
", ";
2840 $sql .=
" note_private = '".$this->db->escape($newprivatenote).
"', date_cloture='".$this->db->idate($now).
"', fk_user_cloture=".((int) $user->id);
2841 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_SIGNED);
2844 $resql = $this->db->query($sql);
2846 $this->errors[] = $this->db->error();
2849 $num = $this->db->affected_rows($resql);
2857 $outputlangs = $langs;
2860 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2861 $outputlangs->setDefaultLang($newlang);
2870 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2873 $this->oldcopy = clone $this;
2876 $this->date_cloture = $now;
2877 $this->note_private = $newprivatenote;
2880 if (!$notrigger && empty($error)) {
2882 $result = $this->call_trigger($triggerName, $user);
2890 $this->db->commit();
2893 foreach ($this->errors as $errmsg) {
2894 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2895 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2897 $this->db->rollback();
2914 $sql =
"UPDATE ". MAIN_DB_PREFIX . $this->table_element;
2915 $sql .=
" SET fk_statut = " . self::STATUS_CANCELED .
",";
2916 $sql .=
" fk_user_modif = " . ((int) $user->id);
2917 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2919 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
2920 if ($this->db->query($sql)) {
2922 $result = $this->call_trigger(
'PROPAL_CANCEL', $user);
2931 $this->db->commit();
2934 foreach ($this->errors as $errmsg) {
2935 dol_syslog(get_class($this).
"::cancel ".$errmsg, LOG_ERR);
2936 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2938 $this->db->rollback();
2942 $this->error = $this->db->error();
2943 $this->db->rollback();
2962 if ($this->
status <= self::STATUS_DRAFT) {
2966 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
2970 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2971 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2972 $sql .=
", online_sign_ip = NULL , online_sign_name = NULL";
2973 $sql .=
" WHERE rowid = ".((int) $this->
id);
2975 $resql = $this->db->query($sql);
2977 $this->errors[] = $this->db->error();
2982 $this->oldcopy = clone $this;
2985 if (!$notrigger && empty($error)) {
2987 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2998 $this->db->commit();
3001 foreach ($this->errors as $errmsg) {
3002 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3003 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3005 $this->db->rollback();
3025 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datep', $sortorder =
'DESC')
3032 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
3033 $sql .=
" p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
3034 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
3035 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.$this->table_element.
" as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
3036 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3037 $sql .=
" AND p.fk_soc = s.rowid";
3038 $sql .=
" AND p.fk_statut = c.id";
3042 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3043 $search_sale = $user->id;
3046 if ($search_sale && $search_sale !=
'-1') {
3047 if ($search_sale == -2) {
3048 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3049 } elseif ($search_sale > 0) {
3050 $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).
")";
3055 $sql .=
" AND p.fk_soc = ".((int) $socid);
3058 $sql .=
" AND p.fk_statut = ".((int) self::STATUS_DRAFT);
3060 if ($notcurrentuser > 0) {
3061 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
3063 $sql .= $this->db->order($sortfield, $sortorder);
3064 $sql .= $this->db->plimit($limit, $offset);
3066 $result = $this->db->query($sql);
3068 $num = $this->db->num_rows($result);
3072 $obj = $this->db->fetch_object($result);
3074 if ($shortlist == 1) {
3075 $ga[$obj->propalid] = $obj->ref;
3076 } elseif ($shortlist == 2) {
3077 $ga[$obj->propalid] = $obj->ref.
' ('.$obj->name.
')';
3079 $ga[$i][
'id'] = $obj->propalid;
3080 $ga[$i][
'ref'] = $obj->ref;
3081 $ga[$i][
'name'] = $obj->name;
3115 $linkedInvoices = array();
3118 foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
3121 foreach ($objectid as $key =>
$object) {
3123 if ($objecttype ==
'facture') {
3128 foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
3129 foreach ($subobjectid as $subkey => $subobject) {
3130 if ($subobjecttype ==
'facture') {
3131 $linkedInvoices[] = $subobject;
3139 if (count($linkedInvoices) > 0) {
3140 $sql =
"SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye";
3141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
3142 $sql .=
" WHERE rowid IN (".$this->db->sanitize(implode(
',', $linkedInvoices)).
")";
3144 dol_syslog(get_class($this).
"::InvoiceArrayList", LOG_DEBUG);
3145 $resql = $this->db->query($sql);
3148 $tab_sqlobj = array();
3149 $nump = $this->db->num_rows($resql);
3150 for ($i = 0; $i < $nump; $i++) {
3151 $obj = $this->db->fetch_object($resql);
3152 $tab_sqlobj[] = $obj;
3154 $this->db->free($resql);
3156 $nump = count($tab_sqlobj);
3160 while ($i < $nump) {
3161 $obj = array_shift($tab_sqlobj);
3184 public function delete($user, $notrigger = 0)
3187 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3195 $result = $this->call_trigger(
'PROPAL_DELETE', $user);
3204 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_propal";
3205 $sql .=
" WHERE fk_propal = ".((int) $this->
id);
3207 $result = $this->db->query($sql);
3210 $this->error = $this->db->lasterror();
3211 $this->errors[] = $this->error;
3216 if (!$error && !empty($this->table_element_line)) {
3217 $tabletodelete = $this->table_element_line;
3218 $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).
")";
3219 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3220 if (!$this->db->query($sqlef) || !$this->db->query($sql)) {
3222 $this->error = $this->db->lasterror();
3223 $this->errors[] = $this->error;
3224 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3249 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3255 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3256 $res = $this->db->query($sql);
3259 $this->error = $this->db->lasterror();
3260 $this->errors[] = $this->error;
3261 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3277 if ($conf->propal->multidir_output[$this->entity] && !empty($this->
ref)) {
3278 $dir =
$conf->propal->multidir_output[$this->entity].
"/".$ref;
3279 $file = $dir.
"/".$ref.
".pdf";
3280 if (file_exists($file)) {
3284 $this->error =
'ErrorFailToDeleteFile';
3285 $this->errors[] = $this->error;
3286 $this->db->rollback();
3290 if (file_exists($dir)) {
3293 $this->error =
'ErrorFailToDeleteDir';
3294 $this->errors[] = $this->error;
3295 $this->db->rollback();
3303 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3304 $this->db->commit();
3307 $this->db->rollback();
3324 if ($this->
status >= self::STATUS_DRAFT) {
3329 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
3330 $sql .=
' SET fk_availability = '.((int) $availability_id);
3331 $sql .=
' WHERE rowid='.((int) $this->
id);
3333 dol_syslog(__METHOD__.
' availability('.$availability_id.
')', LOG_DEBUG);
3334 $resql = $this->db->query($sql);
3336 $this->errors[] = $this->db->error();
3341 $this->oldcopy = clone $this;
3342 $this->availability_id = $availability_id;
3345 if (!$notrigger && empty($error)) {
3347 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
3355 $this->db->commit();
3358 foreach ($this->errors as $errmsg) {
3359 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3360 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3362 $this->db->rollback();
3366 $error_str =
'Propal status do not meet requirement '.$this->status;
3368 $this->error = $error_str;
3369 $this->errors[] = $this->error;
3388 if ($this->
status >= self::STATUS_DRAFT) {
3393 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
3394 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
3395 $sql .=
' WHERE rowid='.((int) $this->
id);
3397 dol_syslog(__METHOD__.
' demand_reason('.$demand_reason_id.
')', LOG_DEBUG);
3398 $resql = $this->db->query($sql);
3400 $this->errors[] = $this->db->error();
3405 $this->oldcopy = clone $this;
3406 $this->demand_reason_id = $demand_reason_id;
3409 if (!$notrigger && empty($error)) {
3411 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
3419 $this->db->commit();
3422 foreach ($this->errors as $errmsg) {
3423 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3424 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3426 $this->db->rollback();
3430 $error_str =
'Propal status do not meet requirement '.$this->status;
3432 $this->error = $error_str;
3433 $this->errors[] = $this->error;
3447 $sql =
"SELECT c.rowid, ";
3448 $sql .=
" c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,";
3449 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
3450 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as c";
3451 $sql .=
" WHERE c.rowid = ".((int) $id);
3453 $result = $this->db->query($sql);
3456 if ($this->db->num_rows($result)) {
3457 $obj = $this->db->fetch_object($result);
3459 $this->
id = $obj->rowid;
3461 $this->date_creation = $this->db->jdate($obj->datec);
3462 $this->date_validation = $this->db->jdate($obj->datev);
3463 $this->date_signature = $this->db->jdate($obj->date_signature);
3464 $this->date_cloture = $this->db->jdate($obj->date_cloture);
3466 $this->user_creation_id = $obj->fk_user_author;
3467 $this->user_validation_id = $obj->fk_user_valid;
3469 if ($obj->fk_user_signature) {
3470 $user_signature =
new User($this->db);
3471 $user_signature->fetch($obj->fk_user_signature);
3472 $this->user_signature = $user_signature;
3475 $this->user_closing_id = $obj->fk_user_cloture;
3477 $this->db->free($result);
3506 global $hookmanager;
3509 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3511 $langs->load(
"propal");
3512 $this->labelStatus[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceled");
3513 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraft");
3514 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidated");
3515 $this->labelStatus[2] = $langs->transnoentitiesnoconv(
"PropalStatusSigned");
3516 $this->labelStatus[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSigned");
3517 $this->labelStatus[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilled");
3518 $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceledShort");
3519 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraftShort");
3520 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidatedShort");
3521 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv(
"PropalStatusSignedShort");
3522 $this->labelStatusShort[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSignedShort");
3523 $this->labelStatusShort[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilledShort");
3527 if ($status == self::STATUS_CANCELED) {
3528 $statusType =
'status9';
3529 } elseif ($status == self::STATUS_DRAFT) {
3530 $statusType =
'status0';
3531 } elseif ($status == self::STATUS_VALIDATED) {
3532 $statusType =
'status1';
3533 } elseif ($status == self::STATUS_SIGNED) {
3534 $statusType =
'status4';
3535 } elseif ($status == self::STATUS_NOTSIGNED) {
3536 $statusType =
'status9';
3537 } elseif ($status == self::STATUS_BILLED) {
3538 $statusType =
'status6';
3541 $parameters = array(
'status' => $status,
'mode' => $mode);
3542 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3545 return $hookmanager->resPrint;
3548 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3563 global $langs, $hookmanager;
3565 $sql =
"SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
3566 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3567 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
3568 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
3570 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3572 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3573 if ($mode ==
'opened') {
3574 $sql .=
" AND p.fk_statut = ".self::STATUS_VALIDATED;
3576 if ($mode ==
'signed') {
3577 $sql .=
" AND p.fk_statut = ".self::STATUS_SIGNED;
3580 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3581 $sql .=
" AND sc.fk_user = ".((int) $user->id);
3584 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3589 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3590 $search_sale = $user->id;
3593 if ($search_sale && $search_sale !=
'-1') {
3594 if ($search_sale == -2) {
3595 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3596 } elseif ($search_sale > 0) {
3597 $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).
")";
3601 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3604 $parameters = array(
'socid' => $user->socid);
3605 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3606 $sql .= $hookmanager->resPrint;
3608 $resql = $this->db->query($sql);
3610 $langs->load(
"propal");
3615 $label = $labelShort =
'';
3616 if ($mode ==
'opened') {
3619 $label = $langs->transnoentitiesnoconv(
"PropalsToClose");
3620 $labelShort = $langs->transnoentitiesnoconv(
"ToAcceptRefuse");
3622 if ($mode ==
'signed') {
3625 $label = $langs->trans(
"PropalsToBill");
3626 $labelShort = $langs->trans(
"ToBill");
3630 $response->warning_delay = $delay_warning / 60 / 60 / 24;
3631 $response->label = $label;
3632 $response->labelShort = $labelShort;
3633 $response->url =
dolBuildUrl(DOL_URL_ROOT.
'/comm/propal/list.php', [
'search_status' => $status,
'mainmenu' =>
'commercial',
'leftmenu' =>
'propals']);
3634 $response->url_late =
dolBuildUrl(DOL_URL_ROOT.
'/comm/propal/list.php', [
'search_option' =>
'late',
'mainmenu' =>
'commercial',
'leftmenu' =>
'propals',
'sortfield' =>
'p.datep',
'sortorder' =>
'asc']);
3638 while ($obj = $this->db->fetch_object($resql)) {
3639 $response->nbtodo++;
3640 $response->total += $obj->total_ht;
3642 if ($mode ==
'opened') {
3643 $datelimit = $this->db->jdate($obj->datefin);
3644 if ($datelimit < ($now - $delay_warning)) {
3645 $response->nbtodolate++;
3654 $this->error = $this->db->error();
3670 global
$conf, $langs;
3675 $sql =
"SELECT rowid";
3676 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3677 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3678 if (array_key_exists(
'tosell', $param)) {
3679 $sql .=
" AND tosell = ".((int) $param[
'tosell']);
3681 $sql .= $this->db->plimit(100);
3683 $resql = $this->db->query($sql);
3685 $num_prods = $this->db->num_rows($resql);
3687 while ($i < $num_prods) {
3689 $row = $this->db->fetch_row($resql);
3690 $prodids[$i] = $row[0];
3696 $this->
ref =
'SPECIMEN';
3697 $this->ref_customer =
'NEMICEPS';
3698 $this->ref_client =
'NEMICEPS';
3699 $this->specimen = 1;
3701 $this->
date = time();
3702 $this->fin_validite = $this->
date + 3600 * 24 * 30;
3703 $this->cond_reglement_id = 1;
3704 $this->cond_reglement_code =
'RECEP';
3705 $this->mode_reglement_id = 7;
3706 $this->mode_reglement_code =
'CHQ';
3707 $this->availability_id = 1;
3708 $this->availability_code =
'AV_NOW';
3709 $this->demand_reason_id = 1;
3710 $this->demand_reason_code =
'SRC_00';
3711 $this->note_public =
'This is a comment (public)';
3712 $this->note_private =
'This is a comment (private)';
3714 $this->multicurrency_tx = 1;
3720 while ($xnbp < $nbp) {
3722 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3724 $line->subprice = 100;
3726 $line->localtax1_tx = 0;
3727 $line->localtax2_tx = 0;
3729 $line->total_ht = 50;
3730 $line->total_ttc = 60;
3731 $line->total_tva = 10;
3732 $line->remise_percent = 50;
3734 $line->total_ht = 100;
3735 $line->total_ttc = 120;
3736 $line->total_tva = 20;
3737 $line->remise_percent = 00;
3740 if ($num_prods > 0) {
3741 $prodid = mt_rand(1, $num_prods);
3742 $line->fk_product = $prodids[$prodid];
3743 $line->product_ref =
'SPECIMEN';
3746 $this->lines[$xnbp] = $line;
3748 $this->total_ht += $line->total_ht;
3749 $this->total_tva += $line->total_tva;
3750 $this->total_ttc += $line->total_ttc;
3765 global $user, $hookmanager;
3767 $this->nb = array();
3769 $sql =
"SELECT count(p.rowid) as nb";
3770 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
3771 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3772 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3776 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3777 $search_sale = $user->id;
3780 if ($search_sale && $search_sale !=
'-1') {
3781 if ($search_sale == -2) {
3782 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3783 } elseif ($search_sale > 0) {
3784 $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).
")";
3789 $parameters = array();
3790 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3791 $sql .= $hookmanager->resPrint;
3792 $resql = $this->db->query($sql);
3795 while ($obj = $this->db->fetch_object($resql)) {
3796 $this->nb[
"proposals"] = $obj->nb;
3798 $this->db->free($resql);
3802 $this->error = $this->db->error();
3815 public function getNextNumRef($soc)
3817 global
$conf, $langs;
3818 $langs->load(
"propal");
3822 if (!empty($classname)) {
3825 $file = $classname.
".php";
3828 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3829 foreach ($dirmodels as $reldir) {
3833 $mybool = ((bool) @include_once $dir.$file) || $mybool;
3841 $obj =
new $classname();
3842 '@phan-var-force ModeleNumRefPropales $obj';
3845 $numref = $obj->getNextValue($soc, $this);
3847 if ($numref !=
"") {
3850 $this->error = $obj->error;
3855 $langs->load(
"errors");
3856 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Proposal"));
3869 global
$conf, $langs, $user;
3871 $langs->load(
'propal');
3873 $nofetch = !empty($params[
'nofetch']);
3876 return [
'optimize' => $langs->trans(
"Proposal")];
3878 if ($user->hasRight(
'propal',
'lire')) {
3879 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly').
'<u>'.$langs->trans(
"Proposal").
'</u>';
3880 if (isset($this->
status)) {
3881 $datas[
'status'] =
' '.$this->getLibStatut(5);
3883 if (!empty($this->
ref)) {
3884 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3887 $langs->load(
'companies');
3888 if (empty($this->thirdparty)) {
3891 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
3893 if (!empty($this->ref_customer)) {
3894 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$this->ref_customer;
3897 $langs->load(
'project');
3898 if (is_null($this->project) || (is_object($this->project) && empty($this->project->id))) {
3900 if ($res > 0 && $this->project instanceof
Project) {
3901 $datas[
'project'] =
'<br><b>'.$langs->trans(
'Project').
':</b> '.$this->project->getNomUrl(1,
'', 0,
'1');
3905 if (!empty($this->total_ht)) {
3906 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
3908 if (!empty($this->total_tva)) {
3909 $datas[
'vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
3911 if (!empty($this->total_ttc)) {
3912 $datas[
'amountttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
3914 if (!empty($this->
date)) {
3915 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
3917 if (!empty($this->date_signature)) {
3918 $datas[
'datesignature'] =
'<br><b>'.$langs->trans(
'DateSigning').
':</b> '.
dol_print_date($this->date_signature,
'day');
3920 if (!empty($this->delivery_date)) {
3921 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3939 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1)
3941 global $langs,
$conf, $user, $hookmanager;
3943 if (!empty(
$conf->dol_no_mouse_hover)) {
3950 'objecttype' => $this->element,
3951 'option' => $option,
3954 $classfortooltip =
'classfortooltip';
3957 $classfortooltip =
'classforajaxtooltip';
3958 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3966 if ($user->hasRight(
'propal',
'lire')) {
3967 parse_str($get_params, $query);
3968 $query = array_merge($query, [
'id' => $this->
id]);
3969 if ($option ==
'') {
3970 $baseurl = DOL_URL_ROOT .
'/comm/propal/card.php';
3971 } elseif ($option ==
'compta') {
3972 $baseurl = DOL_URL_ROOT .
'/comm/propal/card.php';
3973 } elseif ($option ==
'expedition') {
3974 $baseurl = DOL_URL_ROOT .
'/expedition/propal.php';
3975 } elseif ($option ==
'document') {
3976 $baseurl = DOL_URL_ROOT .
'/comm/propal/document.php';
3979 if ($option !=
'nolink') {
3981 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3982 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3983 $add_save_lastsearch_values = 1;
3985 if ($add_save_lastsearch_values) {
3986 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3993 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
3995 $label = $langs->trans(
"Proposal");
3996 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3998 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3999 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
4002 $linkstart =
'<a href="'.$url.
'"';
4003 $linkstart .= $linkclose.
'>';
4006 $result .= $linkstart;
4008 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
4010 if ($withpicto != 2) {
4011 $result .= $this->ref;
4013 $result .= $linkend;
4015 if ($addlinktonotes >= 0) {
4018 if ($addlinktonotes == 0) {
4019 if (!empty($this->note_private) || !empty($this->note_public)) {
4020 $txttoshow = $langs->trans(
'ViewPrivateNote');
4022 } elseif ($addlinktonotes == 1) {
4023 if (!empty($this->note_private)) {
4026 } elseif ($addlinktonotes == 2) {
4027 if (!empty($this->note_public)) {
4030 } elseif ($addlinktonotes == 3) {
4031 if ($user->socid > 0) {
4032 if (!empty($this->note_public)) {
4036 if (!empty($this->note_public)) {
4039 if (!empty($this->note_private)) {
4040 if (!empty($txttoshow)) {
4041 $txttoshow .=
'<br><br>';
4049 $result .=
' <span class="note inline-block">';
4050 $result .=
'<a href="'.dolBuildUrl(DOL_URL_ROOT.
'/comm/propal/note.php', [
'id' => $this->id]).
'" class="classfortooltip" title="'.
dol_escape_htmltag($txttoshow).
'">';
4053 $result .=
'</span>';
4058 $hookmanager->initHooks(array($this->element .
'dao'));
4059 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
4060 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
4062 $result = $hookmanager->resPrint;
4064 $result .= $hookmanager->resPrint;
4077 return $this->
fetch_lines(0, 0, $sqlforgedfilters);
4091 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4093 $outputlangs->loadLangs(array(
"propale",
"products"));
4098 if ($this->model_pdf) {
4099 $modele = $this->model_pdf;
4103 $modelpath =
"core/modules/propale/doc/";
4105 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4153 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
4155 $return =
'<div class="box-flex-item box-flex-grow-zero">';
4156 $return .=
'<div class="info-box info-box-sm">';
4157 $return .=
'<div class="info-box-icon bg-infobox-action">';
4159 $return .=
'</div>';
4160 $return .=
'<div class="info-box-content">';
4161 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
4162 if ($selected >= 0) {
4163 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
4165 if (!empty($arraydata[
'projectlink'])) {
4166 $return .=
'<span class="info-box-ref"> | '.$arraydata[
'projectlink'].
'</span>';
4169 if (is_object($this->thirdparty)) {
4170 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
4172 $return .=
'<span class="info-box-label amount" title="'.$langs->trans(
"AmountHT").
'">'.
price($this->total_ht).
'</span>';
4173 if (!empty($arraydata[
'authorlink'])) {
4174 $return .=
' <span class="info-box-label">'.$arraydata[
'authorlink'].
'</span>';
4176 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
4177 $return .=
'</div>';
4178 $return .=
'</div>';
4179 $return .=
'</div>';
4195 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4196 return parent::setCategoriesCommon($categories, Categorie::TYPE_PROPOSAL);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $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.
roundQtyToPackaging($qty, $packaging)
Round a quantity up to the next multiple of a packaging quantity (options PRODUCT_USE_CUSTOMER_PACKAG...
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
isLineOfObject($lineid)
Check that a line belongs to this object, using $this->table_element_line and $this->fk_element.
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)
checkActiveProductInLines($status='onsale')
Check if all products have the right status (on sale, on buy) called during validation of propal,...
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.
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.
initAsSpecimen($param=array())
Initialise an instance with random values.
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...
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.
setCategories($categories)
Sets object to supplied categories.
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.
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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)
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 '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
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.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getWarningDelay($module, $parmlevel1, $parmlevel2='')
Return a warning delay You can use it like this: if (getWarningDelay('module', 'paramlevel1')) It rep...
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 rate, 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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $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.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date