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 $mode_reglement_code;
254 public $mode_reglement;
261 public $deposit_percent;
273 public $address_type;
284 public $availability_id;
291 public $fk_availability;
296 public $availability_code;
301 public $availability;
306 public $duree_validite;
311 public $demand_reason_id;
316 public $demand_reason_code;
321 public $demand_reason;
326 public $warehouse_id;
331 public $lines = array();
338 public $labelStatus = array();
339 public $labelStatusShort = array();
370 public $fields = array(
371 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
372 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
373 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 20),
374 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 22),
375 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 40),
376 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'position' => 23),
377 '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),
378 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
379 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
380 'datep' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => -1,
'position' => 60),
381 'fin_validite' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' => 1,
'visible' => -1,
'position' => 65),
382 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 70),
383 'date_cloture' => array(
'type' =>
'datetime',
'label' =>
'DateClosing',
'enabled' => 1,
'visible' => -1,
'position' => 75),
384 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 80),
385 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 85),
386 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 90),
387 'fk_user_cloture' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserClosing',
'enabled' => 1,
'visible' => -1,
'position' => 95),
388 'price' => array(
'type' =>
'double',
'label' =>
'Price',
'enabled' => 1,
'visible' => -1,
'position' => 105),
389 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 125,
'isameasure' => 1),
390 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'VAT',
'enabled' => 1,
'visible' => -1,
'position' => 130,
'isameasure' => 1),
391 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax1',
'enabled' => 1,
'visible' => -1,
'position' => 135,
'isameasure' => 1),
392 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax2',
'enabled' => 1,
'visible' => -1,
'position' => 140,
'isameasure' => 1),
393 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 145,
'isameasure' => 1),
394 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 150),
395 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 155),
396 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 160),
397 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 161),
398 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 165),
399 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 170),
400 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 175),
401 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 180),
402 'date_livraison' => array(
'type' =>
'date',
'label' =>
'DateDeliveryPlanned',
'enabled' => 1,
'visible' => -1,
'position' => 185),
403 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMethod',
'enabled' => 1,
'visible' => -1,
'position' => 190),
404 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Fk warehouse',
'enabled' =>
'isModEnabled("stock")',
'visible' => -1,
'position' => 191),
405 'fk_availability' => array(
'type' =>
'integer',
'label' =>
'Availability',
'enabled' => 1,
'visible' => -1,
'position' => 195),
406 'fk_delivery_address' => array(
'type' =>
'integer',
'label' =>
'DeliveryAddress',
'enabled' => 1,
'visible' => 0,
'position' => 200),
407 'fk_input_reason' => array(
'type' =>
'integer',
'label' =>
'InputReason',
'enabled' => 1,
'visible' => -1,
'position' => 205),
408 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 215),
409 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 220),
410 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLabel',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 225),
411 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'MulticurrencyID',
'enabled' => 1,
'visible' => -1,
'position' => 230),
412 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCurrency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
413 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240,
'isameasure' => 1),
414 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 245,
'isameasure' => 1),
415 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 250,
'isameasure' => 1),
416 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 255,
'isameasure' => 1),
417 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 260),
418 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
419 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
460 $this->ismultientitymanaged = 1;
461 $this->socid = $socid;
462 $this->
id = $propalid;
466 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
482 public function add_product($idproduct, $qty, $remise_percent = 0)
491 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
492 if ($idproduct > 0) {
494 $prod->fetch($idproduct);
496 $productdesc =
$prod->description;
500 if (empty($tva_tx)) {
510 $price =
$prod->multiprices[$this->thirdparty->price_level];
512 $price =
$prod->price;
517 $line->fk_product = $idproduct;
518 $line->desc = $productdesc;
520 $line->subprice = $price;
521 $line->remise_percent = $remise_percent;
522 $line->vat_src_code = $vat_src_code;
523 $line->tva_tx = $tva_tx;
524 $line->fk_unit =
$prod->fk_unit;
526 $line->info_bits = 1;
529 $this->lines[] = $line;
547 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
548 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
553 $result = $remise->fetch($idremise);
556 if ($remise->fk_facture) {
557 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
558 $this->db->rollback();
564 $line->context = $this->context;
566 $line->fk_propal = $this->id;
567 $line->fk_remise_except = $remise->id;
568 $line->desc = $remise->description;
569 $line->vat_src_code = $remise->vat_src_code;
570 $line->tva_tx = $remise->tva_tx;
571 $line->localtax1_tx = $remise->localtax1_tx;
572 $line->localtax1_type = $remise->localtax1_type;
573 $line->localtax2_tx = $remise->localtax1_tx;
574 $line->localtax2_type = $remise->localtax1_type;
575 $line->subprice = -(float) $remise->amount_ht;
576 $line->fk_product = 0;
578 $line->remise_percent = 0;
580 $line->info_bits = 2;
582 $line->total_ht = -(float) $remise->amount_ht;
583 $line->total_tva = -(float) $remise->amount_tva;
584 $line->total_ttc = -(float) $remise->amount_ttc;
585 $line->total_localtax1 = -(float) $remise->total_localtax1;
586 $line->total_localtax2 = -(float) $remise->total_localtax2;
588 $result = $line->insert();
595 $this->db->rollback();
600 $this->db->rollback();
604 $this->db->rollback();
654 $remise_percent = 0.0,
655 $price_base_type =
'HT',
667 $array_options = array(),
672 $fk_remise_except = 0,
673 $noupdateafterinsertline = 0
677 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);
679 if ($this->
status == self::STATUS_DRAFT) {
680 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
683 if (empty($remise_percent)) {
689 if (empty($info_bits)) {
695 if (empty($fk_parent_line) || $fk_parent_line < 0) {
699 $remise_percent =
price2num($remise_percent);
702 $pu_ht_devise =
price2num($pu_ht_devise);
704 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
710 if ($price_base_type ==
'HT') {
722 $langs->load(
"errors");
723 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
729 $product_type = $type;
730 if (!empty($fk_product) && $fk_product > 0) {
731 $product =
new Product($this->db);
732 $result = $product->fetch($fk_product);
733 $product_type = $product->type;
735 if ($product->isStockManaged() && $product->stock_reel < $qty &&
getDolGlobalString(
'STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL')) {
736 $langs->load(
"errors");
737 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref);
738 $this->db->rollback();
750 $tmpproduct =
new Product($this->db);
751 $result = $tmpproduct->fetch($fk_product);
752 if (abs((
float) $qty) < $tmpproduct->packaging) {
753 $qty = (float) $tmpproduct->packaging;
754 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
756 if (!empty($tmpproduct->packaging) && (
float)
price2num(fmod((
float) $qty, (
float) $tmpproduct->packaging),
'MS')) {
757 $coeff = intval(abs((
float) $qty) / $tmpproduct->packaging) + 1;
758 $qty =
price2num((
float) $tmpproduct->packaging * $coeff,
'MS');
759 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 $linecount = count($this->lines);
865 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
870 $this->lines[] = $this->line;
873 foreach ($this->lines as $tmpline) {
874 if ($tmpline->id == $origin_id && $tmpline->element == $origin) {
875 $this->line->extraparams = $tmpline->extraparams;
876 $this->line->setExtraParameters();
882 if (empty($noupdateafterinsertline)) {
888 return $this->line->id;
890 $this->error = $this->db->error();
891 $this->db->rollback();
896 $this->db->rollback();
900 dol_syslog(get_class($this).
"::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR);
935 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)
939 dol_syslog(get_class($this).
"::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent,
940 txtva=$txtva, desc=$desc, price_base_type=$price_base_type, info_bits=$info_bits, special_code=$special_code, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, type=$type, date_start=$date_start, date_end=$date_end");
941 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
944 $remise_percent =
price2num($remise_percent);
947 $pu_ht_devise =
price2num($pu_ht_devise);
948 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
954 if (empty($qty) && empty($special_code)) {
957 if (!empty($qty) && $special_code == 3) {
965 $langs->load(
"errors");
966 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
970 if ($this->
status == self::STATUS_DRAFT) {
982 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
983 $vat_src_code = $reg[1];
984 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
989 $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);
990 $total_ht = $tabprice[0];
991 $total_tva = $tabprice[1];
992 $total_ttc = $tabprice[2];
993 $total_localtax1 = $tabprice[9];
994 $total_localtax2 = $tabprice[10];
995 $pu_ht = $tabprice[3];
996 $pu_tva = $tabprice[4];
997 $pu_ttc = $tabprice[5];
1000 $multicurrency_total_ht = $tabprice[16];
1001 $multicurrency_total_tva = $tabprice[17];
1002 $multicurrency_total_ttc = $tabprice[18];
1003 $pu_ht_devise = $tabprice[19];
1007 $line->fetch($rowid);
1009 $staticline = clone $line;
1011 $line->oldline = $staticline;
1012 $this->line = $line;
1013 $this->line->context = $this->context;
1014 $this->line->rang = $rang;
1017 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
1018 $rangmax = $this->
line_max($fk_parent_line);
1019 $this->line->rang = $rangmax + 1;
1023 if (abs((
float) $qty) < $this->line->packaging) {
1024 $qty = $this->line->packaging;
1025 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'warnings');
1027 if (!empty($this->line->packaging)
1028 && is_numeric($this->line->packaging)
1029 && (
float) $this->line->packaging > 0
1030 && (
float)
price2num(fmod((
float) $qty, (
float) $this->line->packaging),
'MS')) {
1031 $coeff = intval(abs((
float) $qty) / $this->line->packaging) + 1;
1032 $qty = $this->line->packaging * $coeff;
1033 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'warnings');
1038 $this->line->id = $rowid;
1039 $this->line->label = $label;
1040 $this->line->desc = $desc;
1041 $this->line->qty = $qty;
1042 $this->line->product_type = $type;
1043 $this->line->vat_src_code = $vat_src_code;
1044 $this->line->tva_tx = $txtva;
1045 $this->line->localtax1_tx = $txlocaltax1;
1046 $this->line->localtax2_tx = $txlocaltax2;
1047 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
1048 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
1049 $this->line->remise_percent = $remise_percent;
1050 $this->line->subprice = (float) $pu_ht;
1052 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
1053 $this->line->info_bits = $info_bits;
1055 $this->line->total_ht = (float) $total_ht;
1056 $this->line->total_tva = (float) $total_tva;
1057 $this->line->total_localtax1 = (float) $total_localtax1;
1058 $this->line->total_localtax2 = (float) $total_localtax2;
1059 $this->line->total_ttc = (float) $total_ttc;
1060 $this->line->special_code = $special_code;
1061 $this->line->fk_parent_line = $fk_parent_line;
1062 $this->line->skip_update_total = $skip_update_total;
1063 $this->line->fk_unit = $fk_unit;
1065 $this->line->fk_fournprice = $fk_fournprice;
1066 $this->line->pa_ht = $pa_ht;
1069 $this->line->date_end = $date_end;
1071 if (is_array($array_options) && count($array_options) > 0) {
1073 foreach ($array_options as $key => $value) {
1074 $this->line->array_options[$key] = $array_options[$key];
1079 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
1080 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
1081 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
1082 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
1084 $result = $this->line->update($notrigger);
1087 if (!empty($fk_parent_line)) {
1097 $this->db->commit();
1101 $this->db->rollback();
1105 dol_syslog(get_class($this).
"::updateline Erreur -2 Propal en mode incompatible pour cette action");
1122 if ($this->
status == self::STATUS_DRAFT) {
1127 $line->context = $this->context;
1130 $line->fetch($lineid);
1132 if ($id > 0 && $line->fk_propal != $id) {
1133 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1138 $staticline = clone $line;
1139 $line->oldline = $staticline;
1141 if ($line->delete($user) > 0) {
1144 $this->db->commit();
1148 $this->db->rollback();
1152 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1166 public function create($user, $notrigger = 0)
1175 if (empty($this->
date)) {
1176 $this->
date = $this->datep;
1178 $this->fin_validite = $this->
date + ($this->duree_validite * 24 * 3600);
1179 if (empty($this->availability_id)) {
1180 $this->availability_id = 0;
1182 if (empty($this->demand_reason_id)) {
1183 $this->demand_reason_id = 0;
1187 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1192 if (empty($this->fk_multicurrency)) {
1194 $this->fk_multicurrency = 0;
1195 $this->multicurrency_tx = 1;
1201 $delivery_date = $this->delivery_date;
1208 $this->error =
"Failed to fetch company";
1209 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1214 if (!empty($this->
ref)) {
1217 $this->error =
'ErrorRefAlreadyExists';
1218 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1219 $this->db->rollback();
1224 if (empty($this->
date)) {
1225 $this->error =
"Date of proposal is required";
1226 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1234 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
1237 $sql .=
", total_tva";
1238 $sql .=
", total_ttc";
1242 $sql .=
", fk_user_author";
1243 $sql .=
", note_private";
1244 $sql .=
", note_public";
1245 $sql .=
", model_pdf";
1246 $sql .=
", fin_validite";
1247 $sql .=
", fk_cond_reglement";
1248 $sql .=
", deposit_percent";
1249 $sql .=
", fk_mode_reglement";
1250 $sql .=
", fk_account";
1251 $sql .=
", ref_client";
1252 $sql .=
", ref_ext";
1253 $sql .=
", date_livraison";
1254 $sql .=
", fk_shipping_method";
1255 $sql .=
", fk_warehouse";
1256 $sql .=
", fk_availability";
1257 $sql .=
", fk_input_reason";
1258 $sql .=
", fk_projet";
1259 $sql .=
", fk_incoterms";
1260 $sql .=
", location_incoterms";
1262 $sql .=
", fk_multicurrency";
1263 $sql .=
", multicurrency_code";
1264 $sql .=
", multicurrency_tx";
1266 $sql .=
" VALUES (";
1267 $sql .= $this->socid;
1271 $sql .=
", '".$this->db->idate($this->
date).
"'";
1272 $sql .=
", '".$this->db->idate($now).
"'";
1273 $sql .=
", '(PROV)'";
1274 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
1275 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1276 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1277 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1278 $sql .=
", ".($this->fin_validite !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
"NULL");
1279 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1280 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
'NULL');
1281 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1282 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1283 $sql .=
", '".$this->db->escape((
string) $this->ref_client).
"'";
1284 $sql .=
", '".$this->db->escape((
string) $this->ref_ext).
"'";
1285 $sql .=
", ".(!
isDolTms($delivery_date) ?
"NULL" :
"'".$this->db->idate($delivery_date).
"'");
1286 $sql .=
", ".($this->shipping_method_id > 0 ? $this->shipping_method_id :
'NULL');
1287 $sql .=
", ".($this->warehouse_id > 0 ? $this->warehouse_id :
'NULL');
1288 $sql .=
", ".((int) $this->availability_id);
1289 $sql .=
", ".((int) $this->demand_reason_id);
1290 $sql .=
", ".($this->fk_project ? $this->fk_project :
"null");
1291 $sql .=
", ".(int) $this->fk_incoterms;
1292 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1293 $sql .=
", ".(int) $this->entity;
1294 $sql .=
", ".(int) $this->fk_multicurrency;
1295 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1296 $sql .=
", ".(float) $this->multicurrency_tx;
1299 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1300 $resql = $this->db->query($sql);
1302 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
1305 $this->
ref =
'(PROV'.$this->id.
')';
1306 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1308 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1309 $resql = $this->db->query($sql);
1314 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1315 $this->linked_objects = $this->linkedObjectsIds;
1319 if (!$error && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1320 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1321 if (is_array($tmp_origin_id)) {
1322 foreach ($tmp_origin_id as $origin_id) {
1325 $this->error = $this->db->lasterror();
1330 $origin_id = $tmp_origin_id;
1333 $this->error = $this->db->lasterror();
1344 $fk_parent_line = 0;
1345 $num = count($this->lines);
1347 for ($i = 0; $i < $num; $i++) {
1348 if (!is_object($this->lines[$i])) {
1350 $line = (object) $this->lines[$i];
1352 $line = $this->lines[$i];
1355 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1356 $fk_parent_line = 0;
1359 $vatrate = $line->tva_tx;
1360 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', $vatrate)) {
1361 $vatrate .=
' ('.$line->vat_src_code.
')';
1365 $originid = $line->origin_id;
1366 $origintype = empty($line->origin_type) ? $line->origin : $line->origin_type;
1368 $originid = $line->id;
1369 $origintype = $this->element;
1377 $line->localtax1_tx,
1378 $line->localtax2_tx,
1380 $line->remise_percent,
1384 $line->product_type,
1386 $line->special_code,
1388 $line->fk_fournprice,
1393 $line->array_options,
1395 (
string) $origintype,
1404 $this->error = $this->db->error;
1410 $line->id = $result;
1413 if ($result > 0 && $line->product_type == 9) {
1414 $fk_parent_line = $result;
1429 if (!$error && !$notrigger) {
1431 $result = $this->call_trigger(
'PROPAL_CREATE', $user);
1438 $this->error = $this->db->lasterror();
1443 $this->error = $this->db->lasterror();
1448 $this->db->commit();
1449 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1452 $this->db->rollback();
1456 $this->error = $this->db->lasterror();
1457 $this->db->rollback();
1472 public function createFromClone(
User $user, $socid = 0, $forceentity =
null, $update_prices =
false, $update_desc =
false)
1483 $object =
new self($this->db);
1490 $objsoc =
new Societe($this->db);
1493 if (!empty($socid) && $socid !=
$object->socid) {
1494 if ($objsoc->fetch($socid) > 0) {
1496 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1497 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
null);
1498 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1499 $object->fk_delivery_address = 0;
1522 $objsoc->fetch(
$object->socid);
1526 if ($update_prices ===
true || $update_desc ===
true) {
1527 if ($objsoc->id > 0 && !empty(
$object->lines)) {
1530 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1533 foreach (
$object->lines as $line) {
1536 if ($line->fk_product > 0) {
1538 $res =
$prod->fetch($line->fk_product);
1540 if ($update_prices ===
true) {
1541 $pu_ht =
$prod->price;
1543 $remise_percent = $objsoc->remise_percent;
1546 $pu_ht =
$prod->multiprices[$objsoc->price_level];
1548 if (isset(
$prod->multiprices_tva_tx[$objsoc->price_level])) {
1549 $tva_tx = (
string)
$prod->multiprices_tva_tx[$objsoc->price_level];
1554 $filter = array(
't.fk_product' => (
string)
$prod->id,
't.fk_soc' => (
string) $objsoc->id);
1555 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1558 if (count($prodcustprice->lines) > 0) {
1559 $date_now = (int) floor(
dol_now() / 86400) * 86400;
1560 foreach ($prodcustprice->lines as $k => $custprice_line) {
1561 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
1562 $pu_ht =
price($custprice_line->price);
1563 $tva_tx = ($custprice_line->default_vat_code ? $custprice_line->tva_tx .
' (' . $custprice_line->default_vat_code .
' )' : $custprice_line->tva_tx);
1564 if ($custprice_line->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
1565 $tva_tx .=
' (' . $custprice_line->default_vat_code .
')';
1567 $remise_percent = $custprice_line->discount_percent;
1575 $line->subprice = $pu_ht;
1576 $line->tva_tx = $tva_tx;
1577 $line->remise_percent = $remise_percent;
1579 if ($update_desc ===
true) {
1580 $line->desc =
$prod->description;
1590 $object->entity = (!empty($forceentity) ? $forceentity :
$object->entity);
1595 $object->user_creation_id = $user->id;
1596 $object->user_validation_id = 0;
1609 $object->context[
'createfromclone'] =
'createfromclone';
1610 $result =
$object->create($user);
1618 if (
$object->copy_linked_contact($this,
'internal') < 0) {
1625 if ($this->socid ==
$object->socid) {
1626 if (
$object->copy_linked_contact($this,
'external') < 0) {
1634 if (is_object($hookmanager)) {
1635 $parameters = array(
'objFrom' => $this,
'clonedObj' =>
$object);
1637 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1645 unset(
$object->context[
'createfromclone']);
1649 $this->db->commit();
1652 $this->db->rollback();
1666 public function fetch($rowid, $ref =
'', $ref_ext =
'', $forceentity = 0)
1668 $sql =
"SELECT p.rowid, p.ref, p.entity, p.fk_soc";
1669 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1670 $sql .=
", p.datec";
1671 $sql .=
", p.date_signature as dates";
1672 $sql .=
", p.date_valid as datev";
1673 $sql .=
", p.date_cloture";
1674 $sql .=
", p.datep as dp";
1675 $sql .=
", p.fin_validite as dfv";
1676 $sql .=
", p.date_livraison as delivery_date";
1677 $sql .=
", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams";
1678 $sql .=
", p.note_private, p.note_public";
1679 $sql .=
", p.fk_projet as fk_project, p.fk_statut";
1680 $sql .=
", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1681 $sql .=
", p.fk_delivery_address";
1682 $sql .=
", p.fk_availability";
1683 $sql .=
", p.fk_input_reason";
1684 $sql .=
", p.fk_cond_reglement";
1685 $sql .=
", p.fk_mode_reglement";
1686 $sql .=
', p.fk_account';
1687 $sql .=
", p.fk_shipping_method";
1688 $sql .=
", p.fk_warehouse";
1689 $sql .=
", p.fk_incoterms, p.location_incoterms";
1690 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1691 $sql .=
", p.tms as date_modification";
1692 $sql .=
", i.libelle as label_incoterms";
1693 $sql .=
", c.label as statut_label";
1694 $sql .=
", ca.code as availability_code, ca.label as availability";
1695 $sql .=
", dr.code as demand_reason_code, dr.label as demand_reason";
1696 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1697 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1698 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
1699 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_propalst as c ON p.fk_statut = c.id';
1700 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.
getEntity(
'c_paiement').
')';
1701 $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').
')';
1702 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON p.fk_availability = ca.rowid';
1703 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
1704 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON p.fk_incoterms = i.rowid';
1707 if (!empty($forceentity)) {
1708 $sql .=
" WHERE p.entity = ".(int) $forceentity;
1710 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
1712 $sql .=
" AND p.ref='".$this->db->escape($ref).
"'";
1715 $sql .=
" WHERE p.rowid = ".((int) $rowid);
1718 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1719 $resql = $this->db->query($sql);
1721 if ($this->db->num_rows($resql)) {
1722 $obj = $this->db->fetch_object($resql);
1724 $this->
id = $obj->rowid;
1725 $this->entity = $obj->entity;
1727 $this->
ref = $obj->ref;
1728 $this->ref_client = $obj->ref_client;
1729 $this->ref_customer = $obj->ref_client;
1730 $this->ref_ext = $obj->ref_ext;
1732 $this->total = $obj->total_ttc;
1733 $this->total_ttc = $obj->total_ttc;
1734 $this->total_ht = $obj->total_ht;
1735 $this->total_tva = $obj->total_tva;
1736 $this->total_localtax1 = $obj->localtax1;
1737 $this->total_localtax2 = $obj->localtax2;
1739 $this->socid = $obj->fk_soc;
1740 $this->thirdparty =
null;
1742 $this->fk_project = $obj->fk_project;
1743 $this->project =
null;
1745 $this->model_pdf = $obj->model_pdf;
1746 $this->last_main_doc = $obj->last_main_doc;
1747 $this->note = $obj->note_private;
1748 $this->note_private = $obj->note_private;
1749 $this->note_public = $obj->note_public;
1751 $this->
status = (int) $obj->fk_statut;
1752 $this->statut = $this->status;
1754 $this->datec = $this->db->jdate($obj->datec);
1755 $this->datev = $this->db->jdate($obj->datev);
1756 $this->date_creation = $this->db->jdate($obj->datec);
1757 $this->date_validation = $this->db->jdate($obj->datev);
1758 $this->date_modification = $this->db->jdate($obj->date_modification);
1759 $this->date_signature = $this->db->jdate($obj->dates);
1760 $this->date_cloture = $this->db->jdate($obj->date_cloture);
1761 $this->
date = $this->db->jdate($obj->dp);
1762 $this->datep = $this->db->jdate($obj->dp);
1763 $this->fin_validite = $this->db->jdate($obj->dfv);
1764 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1765 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1766 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
1767 $this->availability_id = $obj->fk_availability;
1768 $this->availability_code = $obj->availability_code;
1770 $this->demand_reason_id = $obj->fk_input_reason;
1771 $this->demand_reason_code = $obj->demand_reason_code;
1773 $this->fk_address = $obj->fk_delivery_address;
1775 $this->mode_reglement_id = $obj->fk_mode_reglement;
1776 $this->mode_reglement_code = $obj->mode_reglement_code;
1777 $this->mode_reglement = $obj->mode_reglement;
1778 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1779 $this->cond_reglement_id = $obj->fk_cond_reglement;
1780 $this->cond_reglement_code = $obj->cond_reglement_code;
1781 $this->cond_reglement = $obj->cond_reglement;
1782 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1783 $this->deposit_percent = $obj->deposit_percent;
1785 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
1787 $this->user_author_id = $obj->fk_user_author;
1788 $this->user_validation_id = $obj->fk_user_valid;
1789 $this->user_closing_id = $obj->fk_user_cloture;
1792 $this->fk_incoterms = $obj->fk_incoterms;
1793 $this->location_incoterms = $obj->location_incoterms;
1794 $this->label_incoterms = $obj->label_incoterms;
1797 $this->fk_multicurrency = $obj->fk_multicurrency;
1798 $this->multicurrency_code = $obj->multicurrency_code;
1799 $this->multicurrency_tx = $obj->multicurrency_tx;
1800 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1801 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1802 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1808 $this->db->free($resql);
1810 $this->lines = array();
1821 $this->error =
"Record Not Found";
1824 $this->error = $this->db->lasterror();
1841 if (isset($this->
ref)) {
1842 $this->
ref = trim($this->
ref);
1844 if (isset($this->ref_client)) {
1845 $this->ref_client = trim($this->ref_client);
1847 if (isset($this->note) || isset($this->note_private)) {
1848 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1850 if (isset($this->note_public)) {
1851 $this->note_public = trim($this->note_public);
1853 if (isset($this->model_pdf)) {
1854 $this->model_pdf = trim($this->model_pdf);
1856 if (isset($this->import_key)) {
1857 $this->import_key = trim($this->import_key);
1859 if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
1860 $this->fin_validite = $this->
date + ($this->duree_validite * 24 * 3600);
1867 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1868 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal SET";
1869 $sql .=
" ref = ".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1870 $sql .=
" ref_client = ".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
1871 $sql .=
" ref_ext = ".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1872 $sql .=
" fk_soc = ".(!empty($this->socid) ? (int) $this->socid :
"null").
",";
1873 $sql .=
" datep = ".(strval($this->
date) !=
'' ?
"'".$this->db->idate($this->
date).
"'" :
'null').
",";
1874 if (!empty($this->fin_validite)) {
1875 $sql .=
" fin_validite = ".(strval($this->fin_validite) !=
'' ?
"'".$this->db->idate($this->fin_validite).
"'" :
'null').
",";
1877 $sql .=
" date_valid = ".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1878 $sql .=
" total_tva = ".(isset($this->total_tva) ? (float) $this->total_tva :
"null").
",";
1879 $sql .=
" localtax1 = ".(isset($this->total_localtax1) ? (float) $this->total_localtax1 :
"null").
",";
1880 $sql .=
" localtax2 = ".(isset($this->total_localtax2) ? (float) $this->total_localtax2 :
"null").
",";
1881 $sql .=
" total_ht = ".(isset($this->total_ht) ? (float) $this->total_ht :
"null").
",";
1882 $sql .=
" total_ttc = ".(isset($this->total_ttc) ? (float) $this->total_ttc :
"null").
",";
1883 $sql .=
" fk_statut = ".(isset($this->
status) ? (int) $this->
status :
"null").
",";
1884 $sql .=
" fk_user_author = ".(!empty($this->user_author_id) ? (int) $this->user_author_id :
"null").
",";
1885 $sql .=
" fk_user_valid = ".(!empty($this->user_validation_id) ? (int) $this->user_validation_id :
"null").
",";
1887 $sql .=
" fk_projet = ".(!empty($this->fk_project) ? (int) $this->fk_project :
"null").
",";
1888 $sql .=
" fk_cond_reglement = ".(!empty($this->cond_reglement_id) ? (int) $this->cond_reglement_id :
"null").
",";
1889 $sql .=
" deposit_percent = ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1890 $sql .=
" fk_mode_reglement = ".(!empty($this->mode_reglement_id) ? (int) $this->mode_reglement_id :
"null").
",";
1891 $sql .=
" fk_input_reason = ".(!empty($this->demand_reason_id) ? (int) $this->demand_reason_id :
"null").
",";
1892 $sql .=
" fk_shipping_method = ".(isset($this->shipping_method_id) ? (int) $this->shipping_method_id :
"null").
",";
1893 $sql .=
" fk_availability = ".(!empty($this->availability_id) ? (int) $this->availability_id :
"null").
",";
1894 $sql .=
" note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1895 $sql .=
" note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1896 $sql .=
" model_pdf = ".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1897 $sql .=
" import_key = ".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1898 $sql .=
" WHERE rowid = ".((int) $this->
id);
1902 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1903 $resql = $this->db->query($sql);
1906 $this->errors[] =
"Error ".$this->db->lasterror();
1916 if (!$error && !$notrigger) {
1918 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
1927 foreach ($this->errors as $errmsg) {
1928 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1929 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1931 $this->db->rollback();
1934 $this->db->commit();
1949 public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $sqlforgedfilters =
'')
1952 $this->lines = array();
1954 $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,';
1955 $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,';
1956 $sql .=
' d.fk_unit,';
1957 $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,';
1958 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units,';
1959 $sql .=
' p.customcode, p.fk_country as country_id, c.code as country_code,';
1960 $sql .=
' d.date_start, d.date_end, d.extraparams,';
1961 $sql .=
' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc';
1962 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as d';
1963 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (d.fk_product = p.rowid)';
1964 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON c.rowid = p.fk_country';
1965 $sql .=
' WHERE d.fk_propal = '.((int) $this->
id);
1966 if ($only_product) {
1967 $sql .=
' AND p.fk_product_type = 0';
1969 if ($sqlforgedfilters) {
1970 $sql .= $sqlforgedfilters;
1972 $sql .=
' ORDER BY d.rang, d.rowid';
1974 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1975 $result = $this->db->query($sql);
1977 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
1979 $num = $this->db->num_rows($result);
1983 $objp = $this->db->fetch_object($result);
1987 $line->rowid = $objp->rowid;
1988 $line->id = $objp->rowid;
1989 $line->fk_propal = $objp->fk_propal;
1990 $line->fk_parent_line = $objp->fk_parent_line;
1991 $line->label = $objp->custom_label;
1992 $line->desc = $objp->description;
1993 $line->description = $objp->description;
1994 $line->qty = $objp->qty;
1995 $line->vat_src_code = $objp->vat_src_code;
1996 $line->tva_tx = $objp->tva_tx;
1997 $line->localtax1_tx = $objp->localtax1_tx;
1998 $line->localtax2_tx = $objp->localtax2_tx;
1999 $line->localtax1_type = $objp->localtax1_type;
2000 $line->localtax2_type = $objp->localtax2_type;
2001 $line->subprice = $objp->subprice;
2002 $line->subprice_ttc = $objp->subprice_ttc;
2003 $line->fk_remise_except = $objp->fk_remise_except;
2004 $line->remise_percent = $objp->remise_percent;
2006 $line->info_bits = $objp->info_bits;
2007 $line->total_ht = $objp->total_ht;
2008 $line->total_tva = $objp->total_tva;
2009 $line->total_localtax1 = $objp->total_localtax1;
2010 $line->total_localtax2 = $objp->total_localtax2;
2011 $line->total_ttc = $objp->total_ttc;
2012 $line->fk_fournprice = $objp->fk_fournprice;
2013 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
2014 $line->pa_ht = $marginInfos[0];
2015 $line->marge_tx = $marginInfos[1];
2016 $line->marque_tx = $marginInfos[2];
2017 $line->special_code = $objp->special_code;
2018 $line->rang = $objp->rang;
2020 $line->fk_product = $objp->fk_product;
2022 $line->ref = $objp->product_ref;
2023 $line->libelle = $objp->product_label;
2025 $line->product_ref = $objp->product_ref;
2026 $line->product_label = $objp->product_label;
2027 $line->product_desc = $objp->product_desc;
2028 $line->product_tobatch = $objp->product_tobatch;
2029 $line->product_barcode = $objp->product_barcode;
2030 $line->product_custom_code = $objp->customcode;
2031 $line->product_custom_country_id = $objp->country_id;
2032 $line->product_custom_country_code = $objp->country_code;
2033 $line->product_type = $objp->product_type;
2034 $line->fk_product_type = $objp->fk_product_type;
2036 $line->fk_unit = $objp->fk_unit;
2037 $line->weight = $objp->weight;
2038 $line->weight_units = $objp->weight_units;
2039 $line->volume = $objp->volume;
2040 $line->volume_units = $objp->volume_units;
2042 $line->date_start = $this->db->jdate($objp->date_start);
2043 $line->date_end = $this->db->jdate($objp->date_end);
2045 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
2048 $line->fk_multicurrency = $objp->fk_multicurrency;
2049 $line->multicurrency_code = $objp->multicurrency_code;
2050 $line->multicurrency_subprice = $objp->multicurrency_subprice;
2051 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
2052 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
2053 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2055 $line->fetch_optionals();
2058 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
2059 $tmpproduct =
new Product($this->db);
2060 $tmpproduct->fetch($objp->fk_product);
2061 $tmpproduct->getMultiLangs();
2063 $line->multilangs = $tmpproduct->multilangs;
2066 $this->lines[$i] = $line;
2071 $this->db->free($result);
2075 $this->error = $this->db->lasterror();
2087 public function valid($user, $notrigger = 0)
2091 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2096 if ($this->
status == self::STATUS_VALIDATED) {
2097 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
2101 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'creer'))
2102 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'propal',
'propal_advance',
'validate')))) {
2103 $this->error =
'ErrorPermissionDenied';
2104 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
2109 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
2118 $soc =
new Societe($this->db);
2119 $soc->fetch($this->socid);
2122 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
2123 $num = $this->getNextNumRef($soc);
2129 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2130 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
2131 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
", date_valid='".$this->db->idate($now).
"', fk_user_valid=".((int) $user->id);
2134 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
2135 $resql = $this->db->query($sql);
2142 if (!$error && !$notrigger) {
2144 $result = $this->call_trigger(
'PROPAL_VALIDATE', $user);
2152 $this->oldref = $this->ref;
2155 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
2157 $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).
"'";
2158 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
2159 $resql = $this->db->query($sql);
2162 $this->error = $this->db->lasterror();
2164 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'propale/".$this->db->escape($this->newref).
"'";
2165 $sql .=
" WHERE filepath = 'propale/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
2166 $resql = $this->db->query($sql);
2169 $this->error = $this->db->lasterror();
2175 $dirsource =
$conf->propal->multidir_output[$this->entity].
'/'.$oldref;
2176 $dirdest =
$conf->propal->multidir_output[$this->entity].
'/'.$newref;
2177 if (!$error && file_exists($dirsource)) {
2178 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
2179 if (@rename($dirsource, $dirdest)) {
2182 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
2183 foreach ($listoffiles as $fileentry) {
2184 $dirsource = $fileentry[
'name'];
2185 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
2186 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
2187 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
2188 @rename($dirsource, $dirdest);
2197 $this->user_validation_id = $user->id;
2198 $this->datev = $now;
2199 $this->date_validation = $now;
2201 $this->db->commit();
2204 $this->db->rollback();
2223 $this->error =
'ErrorBadParameter';
2224 dol_syslog(get_class($this).
"::set_date ".$this->error, LOG_ERR);
2228 if ($user->hasRight(
'propal',
'creer')) {
2233 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2234 $sql .=
" SET datep = '".$this->db->idate($date).
"'";
2235 $sql .=
" WHERE rowid = ".((int) $this->
id);
2238 $resql = $this->db->query($sql);
2240 $this->errors[] = $this->db->error();
2245 $this->oldcopy = clone $this;
2246 $this->
date = $date;
2247 $this->datep = $date;
2250 if (!$notrigger && empty($error)) {
2252 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2260 $this->db->commit();
2263 foreach ($this->errors as $errmsg) {
2264 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2265 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2267 $this->db->rollback();
2287 if ($user->hasRight(
'propal',
'creer')) {
2292 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2293 $sql .=
" SET fin_validite = ".($date_end_validity !=
'' ?
"'".$this->db->idate($date_end_validity).
"'" :
'null');
2294 $sql .=
" WHERE rowid = ".((int) $this->
id);
2298 $resql = $this->db->query($sql);
2300 $this->errors[] = $this->db->error();
2306 $this->oldcopy = clone $this;
2307 $this->fin_validite = $date_end_validity;
2310 if (!$notrigger && empty($error)) {
2312 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2320 $this->db->commit();
2323 foreach ($this->errors as $errmsg) {
2324 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2325 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2327 $this->db->rollback();
2361 if ($user->hasRight(
'propal',
'creer')) {
2366 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2367 $sql .=
" SET date_livraison = ".(isDolTms($delivery_date) ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2368 $sql .=
" WHERE rowid = ".((int) $this->
id);
2371 $resql = $this->db->query($sql);
2373 $this->errors[] = $this->db->error();
2378 $this->oldcopy = clone $this;
2379 $this->delivery_date = $delivery_date;
2382 if (!$notrigger && empty($error)) {
2384 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2392 $this->db->commit();
2395 foreach ($this->errors as $errmsg) {
2396 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2397 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2399 $this->db->rollback();
2419 if ($this->
status >= self::STATUS_DRAFT) {
2424 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2425 $sql .=
" SET fk_availability = ".((int) ($id > 0 ? $id : 0));
2426 $sql .=
" WHERE rowid = ".((int) $this->
id);
2428 dol_syslog(__METHOD__.
' availability('.$id.
')', LOG_DEBUG);
2429 $resql = $this->db->query($sql);
2431 $this->errors[] = $this->db->error();
2436 $this->oldcopy = clone $this;
2437 $this->fk_availability = $id;
2438 $this->availability_id = $id;
2441 if (!$notrigger && empty($error)) {
2443 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2451 $this->db->commit();
2454 foreach ($this->errors as $errmsg) {
2455 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2456 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2458 $this->db->rollback();
2462 $error_str =
'Propal status do not meet requirement '.$this->status;
2464 $this->error = $error_str;
2465 $this->errors[] = $this->error;
2482 if ($user->hasRight(
'propal',
'creer') && $this->status >= self::STATUS_DRAFT) {
2487 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2488 $sql .=
" SET fk_input_reason = ".((int) $id);
2489 $sql .=
" WHERE rowid = ".((int) $this->
id);
2492 $resql = $this->db->query($sql);
2494 $this->errors[] = $this->db->error();
2500 $this->oldcopy = clone $this;
2502 $this->demand_reason_id = $id;
2506 if (!$notrigger && empty($error)) {
2508 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2516 $this->db->commit();
2519 foreach ($this->errors as $errmsg) {
2520 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2521 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2523 $this->db->rollback();
2527 $error_str =
'Propal status do not meet requirement '.$this->status;
2529 $this->error = $error_str;
2530 $this->errors[] = $this->error;
2547 if ($user->hasRight(
'propal',
'creer')) {
2552 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2553 $sql .=
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
2554 $sql .=
" WHERE rowid = ".((int) $this->
id);
2556 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
2557 $resql = $this->db->query($sql);
2559 $this->errors[] = $this->db->error();
2564 $this->oldcopy = clone $this;
2565 $this->ref_customer = $ref_client;
2566 $this->ref_client = $ref_client;
2569 if (!$notrigger && empty($error)) {
2571 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2579 $this->db->commit();
2582 foreach ($this->errors as $errmsg) {
2583 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2584 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2586 $this->db->rollback();
2604 public function reopen($user, $status, $note =
'', $notrigger = 0)
2608 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2609 $sql .=
" SET fk_statut = ".((int) $status).
",";
2610 if (!empty($note)) {
2611 $sql .=
" note_private = '".$this->db->escape($note).
"',";
2613 $sql .=
" date_cloture=NULL, fk_user_cloture=NULL";
2614 $sql .=
" WHERE rowid = ".((int) $this->
id);
2618 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
2619 $resql = $this->db->query($sql);
2622 $this->errors[] =
"Error ".$this->db->lasterror();
2627 $result = $this->call_trigger(
'PROPAL_REOPEN', $user);
2637 if (!empty($this->errors)) {
2638 foreach ($this->errors as $errmsg) {
2639 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2640 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2643 $this->db->rollback();
2646 $this->statut = $status;
2649 $this->db->commit();
2664 public function closeProposal($user, $status, $note_private =
'', $notrigger = 0, $note_public =
'')
2666 global $langs,
$conf;
2673 $newprivatenote =
dol_concatdesc($this->note_private, $note_private);
2674 $newpublicnote =
dol_concatdesc($this->note_public, $note_public);
2677 $date_signature = $now;
2678 $fk_user_signature = $user->id;
2680 $this->
info($this->
id);
2681 if (!isset($this->date_signature) || $this->date_signature ==
'') {
2682 $date_signature = $now;
2683 $fk_user_signature = $user->id;
2685 $date_signature = $this->date_signature;
2686 $fk_user_signature = $this->user_signature->id;
2690 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2691 $sql .=
" SET fk_statut = ".((int) $status).
", note_private = '".$this->db->escape($newprivatenote).
"', note_public = '".$this->db->escape($newpublicnote).
"'";
2692 if ($status == self::STATUS_SIGNED) {
2693 $sql .=
", date_signature='".$this->db->idate($now).
"', fk_user_signature = ".($fk_user_signature);
2695 $sql .=
" WHERE rowid = ".((int) $this->
id);
2697 $resql = $this->db->query($sql);
2701 $triggerName =
'PROPAL_CLOSE_REFUSED';
2703 if ($status == self::STATUS_SIGNED) {
2704 $triggerName =
'PROPAL_CLOSE_SIGNED';
2708 $soc =
new Societe($this->db);
2709 $soc->id = $this->socid;
2710 $result = $soc->setAsCustomer();
2713 $this->error = $this->db->lasterror();
2714 $this->db->rollback();
2721 $outputlangs = $langs;
2724 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2725 $outputlangs->setDefaultLang($newlang);
2734 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2737 $this->oldcopy = clone $this;
2738 $this->statut = $status;
2740 $this->date_signature = $date_signature;
2741 $this->note_private = $newprivatenote;
2743 if (!$notrigger && empty($error)) {
2745 $result = $this->call_trigger($triggerName, $user);
2753 $this->db->commit();
2756 foreach ($this->errors as $errmsg) {
2757 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2758 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2760 if (!empty($this->oldcopy)) {
2761 $this->statut = $this->oldcopy->status;
2762 $this->
status = $this->oldcopy->status;
2763 $this->date_signature = $this->oldcopy->date_signature;
2764 $this->note_private = $this->oldcopy->note_private;
2767 $this->db->rollback();
2771 $this->error = $this->db->lasterror();
2772 $this->db->rollback();
2787 global
$conf, $langs;
2794 $triggerName =
'PROPAL_CLASSIFY_BILLED';
2800 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2801 $sql .=
" SET fk_statut = ".self::STATUS_BILLED.
", ";
2802 $sql .=
" note_private = '".$this->db->escape($newprivatenote).
"', date_cloture='".$this->db->idate($now).
"', fk_user_cloture=".((int) $user->id);
2803 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_SIGNED);
2806 $resql = $this->db->query($sql);
2808 $this->errors[] = $this->db->error();
2811 $num = $this->db->affected_rows($resql);
2819 $outputlangs = $langs;
2822 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
2823 $outputlangs->setDefaultLang($newlang);
2832 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2835 $this->oldcopy = clone $this;
2838 $this->date_cloture = $now;
2839 $this->note_private = $newprivatenote;
2842 if (!$notrigger && empty($error)) {
2844 $result = $this->call_trigger($triggerName, $user);
2852 $this->db->commit();
2855 foreach ($this->errors as $errmsg) {
2856 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2857 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2859 $this->db->rollback();
2876 $sql =
"UPDATE ". MAIN_DB_PREFIX . $this->table_element;
2877 $sql .=
" SET fk_statut = " . self::STATUS_CANCELED .
",";
2878 $sql .=
" fk_user_modif = " . ((int) $user->id);
2879 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2881 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
2882 if ($this->db->query($sql)) {
2884 $result = $this->call_trigger(
'PROPAL_CANCEL', $user);
2893 $this->db->commit();
2896 foreach ($this->errors as $errmsg) {
2897 dol_syslog(get_class($this).
"::cancel ".$errmsg, LOG_ERR);
2898 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2900 $this->db->rollback();
2904 $this->error = $this->db->error();
2905 $this->db->rollback();
2924 if ($this->
status <= self::STATUS_DRAFT) {
2928 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
2932 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2933 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2934 $sql .=
", online_sign_ip = NULL , online_sign_name = NULL";
2935 $sql .=
" WHERE rowid = ".((int) $this->
id);
2937 $resql = $this->db->query($sql);
2939 $this->errors[] = $this->db->error();
2944 $this->oldcopy = clone $this;
2947 if (!$notrigger && empty($error)) {
2949 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
2960 $this->db->commit();
2963 foreach ($this->errors as $errmsg) {
2964 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2965 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2967 $this->db->rollback();
2987 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datep', $sortorder =
'DESC')
2994 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
2995 $sql .=
" p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
2996 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
2997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.$this->table_element.
" as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
2998 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
2999 $sql .=
" AND p.fk_soc = s.rowid";
3000 $sql .=
" AND p.fk_statut = c.id";
3004 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3005 $search_sale = $user->id;
3008 if ($search_sale && $search_sale !=
'-1') {
3009 if ($search_sale == -2) {
3010 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3011 } elseif ($search_sale > 0) {
3012 $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).
")";
3017 $sql .=
" AND p.fk_soc = ".((int) $socid);
3020 $sql .=
" AND p.fk_statut = ".((int) self::STATUS_DRAFT);
3022 if ($notcurrentuser > 0) {
3023 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
3025 $sql .= $this->db->order($sortfield, $sortorder);
3026 $sql .= $this->db->plimit($limit, $offset);
3028 $result = $this->db->query($sql);
3030 $num = $this->db->num_rows($result);
3034 $obj = $this->db->fetch_object($result);
3036 if ($shortlist == 1) {
3037 $ga[$obj->propalid] = $obj->ref;
3038 } elseif ($shortlist == 2) {
3039 $ga[$obj->propalid] = $obj->ref.
' ('.$obj->name.
')';
3041 $ga[$i][
'id'] = $obj->propalid;
3042 $ga[$i][
'ref'] = $obj->ref;
3043 $ga[$i][
'name'] = $obj->name;
3077 $linkedInvoices = array();
3080 foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
3083 foreach ($objectid as $key =>
$object) {
3085 if ($objecttype ==
'facture') {
3090 foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
3091 foreach ($subobjectid as $subkey => $subobject) {
3092 if ($subobjecttype ==
'facture') {
3093 $linkedInvoices[] = $subobject;
3101 if (count($linkedInvoices) > 0) {
3102 $sql =
"SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye";
3103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
3104 $sql .=
" WHERE rowid IN (".$this->db->sanitize(implode(
',', $linkedInvoices)).
")";
3106 dol_syslog(get_class($this).
"::InvoiceArrayList", LOG_DEBUG);
3107 $resql = $this->db->query($sql);
3110 $tab_sqlobj = array();
3111 $nump = $this->db->num_rows($resql);
3112 for ($i = 0; $i < $nump; $i++) {
3113 $sqlobj = $this->db->fetch_object($resql);
3114 $tab_sqlobj[] = $sqlobj;
3116 $this->db->free($resql);
3118 $nump = count($tab_sqlobj);
3122 while ($i < $nump) {
3123 $obj = array_shift($tab_sqlobj);
3146 public function delete($user, $notrigger = 0)
3149 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3157 $result = $this->call_trigger(
'PROPAL_DELETE', $user);
3165 if (!$error && !empty($this->table_element_line)) {
3166 $tabletodelete = $this->table_element_line;
3167 $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).
")";
3168 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3169 if (!$this->db->query($sqlef) || !$this->db->query($sql)) {
3171 $this->error = $this->db->lasterror();
3172 $this->errors[] = $this->error;
3173 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3198 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3204 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3205 $res = $this->db->query($sql);
3208 $this->error = $this->db->lasterror();
3209 $this->errors[] = $this->error;
3210 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3226 if ($conf->propal->multidir_output[$this->entity] && !empty($this->
ref)) {
3227 $dir =
$conf->propal->multidir_output[$this->entity].
"/".$ref;
3228 $file = $dir.
"/".$ref.
".pdf";
3229 if (file_exists($file)) {
3233 $this->error =
'ErrorFailToDeleteFile';
3234 $this->errors[] = $this->error;
3235 $this->db->rollback();
3239 if (file_exists($dir)) {
3242 $this->error =
'ErrorFailToDeleteDir';
3243 $this->errors[] = $this->error;
3244 $this->db->rollback();
3252 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3253 $this->db->commit();
3256 $this->db->rollback();
3273 if ($this->
status >= self::STATUS_DRAFT) {
3278 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
3279 $sql .=
' SET fk_availability = '.((int) $availability_id);
3280 $sql .=
' WHERE rowid='.((int) $this->
id);
3282 dol_syslog(__METHOD__.
' availability('.$availability_id.
')', LOG_DEBUG);
3283 $resql = $this->db->query($sql);
3285 $this->errors[] = $this->db->error();
3290 $this->oldcopy = clone $this;
3291 $this->availability_id = $availability_id;
3294 if (!$notrigger && empty($error)) {
3296 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
3304 $this->db->commit();
3307 foreach ($this->errors as $errmsg) {
3308 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3309 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3311 $this->db->rollback();
3315 $error_str =
'Propal status do not meet requirement '.$this->status;
3317 $this->error = $error_str;
3318 $this->errors[] = $this->error;
3337 if ($this->
status >= self::STATUS_DRAFT) {
3342 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
3343 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
3344 $sql .=
' WHERE rowid='.((int) $this->
id);
3346 dol_syslog(__METHOD__.
' demand_reason('.$demand_reason_id.
')', LOG_DEBUG);
3347 $resql = $this->db->query($sql);
3349 $this->errors[] = $this->db->error();
3354 $this->oldcopy = clone $this;
3355 $this->demand_reason_id = $demand_reason_id;
3358 if (!$notrigger && empty($error)) {
3360 $result = $this->call_trigger(
'PROPAL_MODIFY', $user);
3368 $this->db->commit();
3371 foreach ($this->errors as $errmsg) {
3372 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3373 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3375 $this->db->rollback();
3379 $error_str =
'Propal status do not meet requirement '.$this->status;
3381 $this->error = $error_str;
3382 $this->errors[] = $this->error;
3396 $sql =
"SELECT c.rowid, ";
3397 $sql .=
" c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,";
3398 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
3399 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as c";
3400 $sql .=
" WHERE c.rowid = ".((int) $id);
3402 $result = $this->db->query($sql);
3405 if ($this->db->num_rows($result)) {
3406 $obj = $this->db->fetch_object($result);
3408 $this->
id = $obj->rowid;
3410 $this->date_creation = $this->db->jdate($obj->datec);
3411 $this->date_validation = $this->db->jdate($obj->datev);
3412 $this->date_signature = $this->db->jdate($obj->date_signature);
3413 $this->date_cloture = $this->db->jdate($obj->date_cloture);
3415 $this->user_creation_id = $obj->fk_user_author;
3416 $this->user_validation_id = $obj->fk_user_valid;
3418 if ($obj->fk_user_signature) {
3419 $user_signature =
new User($this->db);
3420 $user_signature->fetch($obj->fk_user_signature);
3421 $this->user_signature = $user_signature;
3424 $this->user_closing_id = $obj->fk_user_cloture;
3426 $this->db->free($result);
3455 global $hookmanager;
3458 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3460 $langs->load(
"propal");
3461 $this->labelStatus[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceled");
3462 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraft");
3463 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidated");
3464 $this->labelStatus[2] = $langs->transnoentitiesnoconv(
"PropalStatusSigned");
3465 $this->labelStatus[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSigned");
3466 $this->labelStatus[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilled");
3467 $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv(
"PropalStatusCanceledShort");
3468 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"PropalStatusDraftShort");
3469 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"PropalStatusValidatedShort");
3470 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv(
"PropalStatusSignedShort");
3471 $this->labelStatusShort[3] = $langs->transnoentitiesnoconv(
"PropalStatusNotSignedShort");
3472 $this->labelStatusShort[4] = $langs->transnoentitiesnoconv(
"PropalStatusBilledShort");
3476 if ($status == self::STATUS_CANCELED) {
3477 $statusType =
'status9';
3478 } elseif ($status == self::STATUS_DRAFT) {
3479 $statusType =
'status0';
3480 } elseif ($status == self::STATUS_VALIDATED) {
3481 $statusType =
'status1';
3482 } elseif ($status == self::STATUS_SIGNED) {
3483 $statusType =
'status4';
3484 } elseif ($status == self::STATUS_NOTSIGNED) {
3485 $statusType =
'status9';
3486 } elseif ($status == self::STATUS_BILLED) {
3487 $statusType =
'status6';
3490 $parameters = array(
'status' => $status,
'mode' => $mode);
3491 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3494 return $hookmanager->resPrint;
3497 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3512 global $langs, $hookmanager;
3514 $sql =
"SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
3515 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3516 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
3517 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
3519 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propal as p";
3521 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3522 if ($mode ==
'opened') {
3523 $sql .=
" AND p.fk_statut = ".self::STATUS_VALIDATED;
3525 if ($mode ==
'signed') {
3526 $sql .=
" AND p.fk_statut = ".self::STATUS_SIGNED;
3529 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3530 $sql .=
" AND sc.fk_user = ".((int) $user->id);
3533 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3538 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3539 $search_sale = $user->id;
3542 if ($search_sale && $search_sale !=
'-1') {
3543 if ($search_sale == -2) {
3544 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3545 } elseif ($search_sale > 0) {
3546 $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).
")";
3550 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3553 $parameters = array(
'socid' => $user->socid);
3554 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3555 $sql .= $hookmanager->resPrint;
3557 $resql = $this->db->query($sql);
3559 $langs->load(
"propal");
3564 $label = $labelShort =
'';
3565 if ($mode ==
'opened') {
3568 $label = $langs->transnoentitiesnoconv(
"PropalsToClose");
3569 $labelShort = $langs->transnoentitiesnoconv(
"ToAcceptRefuse");
3571 if ($mode ==
'signed') {
3574 $label = $langs->trans(
"PropalsToBill");
3575 $labelShort = $langs->trans(
"ToBill");
3579 $response->warning_delay = $delay_warning / 60 / 60 / 24;
3580 $response->label = $label;
3581 $response->labelShort = $labelShort;
3582 $response->url =
dolBuildUrl(DOL_URL_ROOT.
'/comm/propal/list.php', [
'search_status' => $status,
'mainmenu' =>
'commercial',
'leftmenu' =>
'propals']);
3583 $response->url_late =
dolBuildUrl(DOL_URL_ROOT.
'/comm/propal/list.php', [
'search_option' =>
'late',
'mainmenu' =>
'commercial',
'leftmenu' =>
'propals',
'sortfield' =>
'p.datep',
'sortorder' =>
'asc']);
3587 while ($obj = $this->db->fetch_object($resql)) {
3588 $response->nbtodo++;
3589 $response->total += $obj->total_ht;
3591 if ($mode ==
'opened') {
3592 $datelimit = $this->db->jdate($obj->datefin);
3593 if ($datelimit < ($now - $delay_warning)) {
3594 $response->nbtodolate++;
3603 $this->error = $this->db->error();
3619 global
$conf, $langs;
3624 $sql =
"SELECT rowid";
3625 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3626 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3627 if (array_key_exists(
'tosell', $param)) {
3628 $sql .=
" AND tosell = ".((int) $param[
'tosell']);
3630 $sql .= $this->db->plimit(100);
3632 $resql = $this->db->query($sql);
3634 $num_prods = $this->db->num_rows($resql);
3636 while ($i < $num_prods) {
3638 $row = $this->db->fetch_row($resql);
3639 $prodids[$i] = $row[0];
3645 $this->
ref =
'SPECIMEN';
3646 $this->ref_customer =
'NEMICEPS';
3647 $this->ref_client =
'NEMICEPS';
3648 $this->specimen = 1;
3650 $this->
date = time();
3651 $this->fin_validite = $this->
date + 3600 * 24 * 30;
3652 $this->cond_reglement_id = 1;
3653 $this->cond_reglement_code =
'RECEP';
3654 $this->mode_reglement_id = 7;
3655 $this->mode_reglement_code =
'CHQ';
3656 $this->availability_id = 1;
3657 $this->availability_code =
'AV_NOW';
3658 $this->demand_reason_id = 1;
3659 $this->demand_reason_code =
'SRC_00';
3660 $this->note_public =
'This is a comment (public)';
3661 $this->note_private =
'This is a comment (private)';
3663 $this->multicurrency_tx = 1;
3669 while ($xnbp < $nbp) {
3671 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3673 $line->subprice = 100;
3675 $line->localtax1_tx = 0;
3676 $line->localtax2_tx = 0;
3678 $line->total_ht = 50;
3679 $line->total_ttc = 60;
3680 $line->total_tva = 10;
3681 $line->remise_percent = 50;
3683 $line->total_ht = 100;
3684 $line->total_ttc = 120;
3685 $line->total_tva = 20;
3686 $line->remise_percent = 00;
3689 if ($num_prods > 0) {
3690 $prodid = mt_rand(1, $num_prods);
3691 $line->fk_product = $prodids[$prodid];
3692 $line->product_ref =
'SPECIMEN';
3695 $this->lines[$xnbp] = $line;
3697 $this->total_ht += $line->total_ht;
3698 $this->total_tva += $line->total_tva;
3699 $this->total_ttc += $line->total_ttc;
3714 global $user, $hookmanager;
3716 $this->nb = array();
3718 $sql =
"SELECT count(p.rowid) as nb";
3719 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as p";
3720 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3721 $sql .=
" WHERE p.entity IN (".getEntity(
'propal').
")";
3725 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3726 $search_sale = $user->id;
3729 if ($search_sale && $search_sale !=
'-1') {
3730 if ($search_sale == -2) {
3731 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
3732 } elseif ($search_sale > 0) {
3733 $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).
")";
3738 $parameters = array();
3739 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3740 $sql .= $hookmanager->resPrint;
3741 $resql = $this->db->query($sql);
3744 while ($obj = $this->db->fetch_object($resql)) {
3745 $this->nb[
"proposals"] = $obj->nb;
3747 $this->db->free($resql);
3751 $this->error = $this->db->error();
3764 public function getNextNumRef($soc)
3766 global
$conf, $langs;
3767 $langs->load(
"propal");
3771 if (!empty($classname)) {
3774 $file = $classname.
".php";
3777 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3778 foreach ($dirmodels as $reldir) {
3782 $mybool = ((bool) @include_once $dir.$file) || $mybool;
3790 $obj =
new $classname();
3791 '@phan-var-force ModeleNumRefPropales $obj';
3794 $numref = $obj->getNextValue($soc, $this);
3796 if ($numref !=
"") {
3799 $this->error = $obj->error;
3804 $langs->load(
"errors");
3805 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Proposal"));
3818 global
$conf, $langs, $user;
3820 $langs->load(
'propal');
3822 $nofetch = !empty($params[
'nofetch']);
3825 return [
'optimize' => $langs->trans(
"Proposal")];
3827 if ($user->hasRight(
'propal',
'lire')) {
3828 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly').
'<u>'.$langs->trans(
"Proposal").
'</u>';
3829 if (isset($this->
status)) {
3830 $datas[
'status'] =
' '.$this->getLibStatut(5);
3832 if (!empty($this->
ref)) {
3833 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3836 $langs->load(
'companies');
3837 if (empty($this->thirdparty)) {
3840 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
3842 if (!empty($this->ref_customer)) {
3843 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$this->ref_customer;
3846 $langs->load(
'project');
3847 if (is_null($this->project) || (is_object($this->project) && $this->project->isEmpty())) {
3849 if ($res > 0 && $this->project instanceof
Project) {
3850 $datas[
'project'] =
'<br><b>'.$langs->trans(
'Project').
':</b> '.$this->project->getNomUrl(1,
'', 0,
'1');
3854 if (!empty($this->total_ht)) {
3855 $datas[
'amountht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
3857 if (!empty($this->total_tva)) {
3858 $datas[
'vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
3860 if (!empty($this->total_ttc)) {
3861 $datas[
'amountttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
3863 if (!empty($this->
date)) {
3864 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
3866 if (!empty($this->date_signature)) {
3867 $datas[
'datesignature'] =
'<br><b>'.$langs->trans(
'DateSigning').
':</b> '.
dol_print_date($this->date_signature,
'day');
3869 if (!empty($this->delivery_date)) {
3870 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3888 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1)
3890 global $langs,
$conf, $user, $hookmanager;
3892 if (!empty(
$conf->dol_no_mouse_hover)) {
3899 'objecttype' => $this->element,
3900 'option' => $option,
3903 $classfortooltip =
'classfortooltip';
3906 $classfortooltip =
'classforajaxtooltip';
3907 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3915 if ($user->hasRight(
'propal',
'lire')) {
3916 parse_str($get_params, $query);
3917 $query = array_merge($query, [
'id' => $this->
id]);
3918 if ($option ==
'') {
3919 $baseurl = DOL_URL_ROOT .
'/comm/propal/card.php';
3920 } elseif ($option ==
'compta') {
3921 $baseurl = DOL_URL_ROOT .
'/comm/propal/card.php';
3922 } elseif ($option ==
'expedition') {
3923 $baseurl = DOL_URL_ROOT .
'/expedition/propal.php';
3924 } elseif ($option ==
'document') {
3925 $baseurl = DOL_URL_ROOT .
'/comm/propal/document.php';
3928 if ($option !=
'nolink') {
3930 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3931 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3932 $add_save_lastsearch_values = 1;
3934 if ($add_save_lastsearch_values) {
3935 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3942 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
3944 $label = $langs->trans(
"Proposal");
3945 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3947 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3948 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
3951 $linkstart =
'<a href="'.$url.
'"';
3952 $linkstart .= $linkclose.
'>';
3955 $result .= $linkstart;
3957 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
3959 if ($withpicto != 2) {
3960 $result .= $this->ref;
3962 $result .= $linkend;
3964 if ($addlinktonotes >= 0) {
3967 if ($addlinktonotes == 0) {
3968 if (!empty($this->note_private) || !empty($this->note_public)) {
3969 $txttoshow = $langs->trans(
'ViewPrivateNote');
3971 } elseif ($addlinktonotes == 1) {
3972 if (!empty($this->note_private)) {
3975 } elseif ($addlinktonotes == 2) {
3976 if (!empty($this->note_public)) {
3979 } elseif ($addlinktonotes == 3) {
3980 if ($user->socid > 0) {
3981 if (!empty($this->note_public)) {
3985 if (!empty($this->note_public)) {
3988 if (!empty($this->note_private)) {
3989 if (!empty($txttoshow)) {
3990 $txttoshow .=
'<br><br>';
3998 $result .=
' <span class="note inline-block">';
3999 $result .=
'<a href="'.dolBuildUrl(DOL_URL_ROOT.
'/comm/propal/note.php', [
'id' => $this->id]).
'" class="classfortooltip" title="'.
dol_escape_htmltag($txttoshow).
'">';
4002 $result .=
'</span>';
4007 $hookmanager->initHooks(array($this->element .
'dao'));
4008 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
4009 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
4011 $result = $hookmanager->resPrint;
4013 $result .= $hookmanager->resPrint;
4026 return $this->
fetch_lines(0, 0, $sqlforgedfilters);
4040 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4042 $outputlangs->loadLangs(array(
"propale",
"products"));
4047 if ($this->model_pdf) {
4048 $modele = $this->model_pdf;
4052 $modelpath =
"core/modules/propale/doc/";
4054 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4102 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
4104 $return =
'<div class="box-flex-item box-flex-grow-zero">';
4105 $return .=
'<div class="info-box info-box-sm">';
4106 $return .=
'<div class="info-box-icon bg-infobox-action">';
4108 $return .=
'</div>';
4109 $return .=
'<div class="info-box-content">';
4110 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
4111 if ($selected >= 0) {
4112 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
4114 if (!empty($arraydata[
'projectlink'])) {
4115 $return .=
'<span class="info-box-ref"> | '.$arraydata[
'projectlink'].
'</span>';
4118 if (is_object($this->thirdparty)) {
4119 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
4121 $return .=
'<span class="info-box-label amount" title="'.$langs->trans(
"AmountHT").
'">'.
price($this->total_ht).
'</span>';
4122 if (!empty($arraydata[
'authorlink'])) {
4123 $return .=
' <span class="info-box-label">'.$arraydata[
'authorlink'].
'</span>';
4125 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
4126 $return .=
'</div>';
4127 $return .=
'</div>';
4128 $return .=
'</div>';
4144 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4145 return parent::setCategoriesCommon($categories, Categorie::TYPE_PROPOSAL);
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.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetchProject()
Load the project with id $this->fk_project into this->project.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
updateRangOfLine($rowid, $rang)
Update position of line (rang)
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 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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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.
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', ...)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_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...
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, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
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