From 9ef27355205dc9067792b8a37271ce07c1d602a1 Mon Sep 17 00:00:00 2001 From: Vincent Dieltiens Date: Thu, 2 Dec 2021 18:25:14 +0100 Subject: [PATCH 1/8] Adds import for customer invoices and invoices lines --- .../facture/class/paymentterm.class.php | 10 +- htdocs/core/modules/modFacture.class.php | 268 ++++++++++++++++++ 2 files changed, 276 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index f94ad573a81..143f4bcf746 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -172,9 +172,10 @@ class PaymentTerm // extends CommonObject * Load object in memory from database * * @param int $id Id object + * @param string $code * @return int <0 if KO, >0 if OK */ - public function fetch($id) + public function fetch($id, $code = '') { global $langs; $sql = "SELECT"; @@ -192,7 +193,12 @@ class PaymentTerm // extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; - $sql .= " WHERE t.rowid = ".((int) $id); + if ($id) { + $sql .= " WHERE t.rowid = ".((int) $id); + } + if ($code) { + $sql .= " WHERE t.code='".$this->db->escape($code)."' AND t.entity IN (".getEntity('payment_term').")"; + } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index ef341c83e89..73ca71bcf73 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -232,6 +232,274 @@ class modFacture extends DolibarrModules $this->menu = 1; // This module add menu entries. They are coded into menu manager. + // Imports + //-------- + $r = 1; + + $r++; + $this->import_code[$r] = $this->rights_class.'_'.$r; + $this->import_label[$r] = "Invoices"; // Translation key + $this->import_icon[$r] = $this->picto; + $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture', 'extra' => MAIN_DB_PREFIX.'facture_extrafields'); + $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id + $this->import_fields_array[$r] = array( + 'f.ref' => 'InvoiceRef*', + 'f.ref_ext' => 'ExternalRef', + 'f.ref_int' => 'ExternalRef', + 'f.ref_client' => 'CutomerRef', + 'f.type' => 'Type*', + 'f.fk_soc' => 'Customer*', + 'f.datec' => 'InvoiceDateCreation', + 'f.datef' => 'DateInvoice', + 'f.date_valid' => 'Validation Date', + 'f.paye' => 'InvoicePaid', + 'f.remise_percent' => 'RemisePercent', + 'f.remise_absolue' => 'RemiseAbsolue', + 'f.remise' => 'Remise', + 'f.total_tva' => 'TotalVAT', + 'f.total_ht' => 'TotalHT', + 'f.total_ttc' => 'TotalTTC', + 'f.fk_statut' => 'InvoiceStatus', + 'f.fk_user_modif' => 'Modifier Id', + 'f.fk_user_valid' => 'Validator Id', + 'f.fk_user_closing' => 'Closer Id', + 'f.fk_facture_source' => 'Invoice Source Id', + 'f.fk_projet' => 'Project Id', + 'f.fk_account' => 'Bank Account', + 'f.fk_currency' => 'Currency*', + 'f.fk_cond_reglement' => 'Payment Condition', + 'f.fk_mode_reglement' => 'Payment Mode', + 'f.date_lim_reglement' => 'DateMaxPayment', + 'f.note_public' => 'InvoiceNote', + 'f.note_private' => 'NotePrivate', + 'f.model_pdf' => 'Model' + ); + if (!empty($conf->multicurrency->enabled)) { + $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency'; + $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate'; + $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; + $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; + $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; + } + // Add extra fields + $import_extrafield_sample = array(); + $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture' AND entity IN (0, ".$conf->entity.")"; + $resql = $this->db->query($sql); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $fieldname = 'extra.'.$obj->name; + $fieldlabel = ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : ''); + $import_extrafield_sample[$fieldname] = $fieldlabel; + } + } + // End add extra fields + $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture'); + $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'); + $import_sample = array( + 'f.ref' => '(PROV0001)', + 'f.ref_ext' => '', + 'f.ref_int' => '', + 'f.ref_client' => '', + 'f.type' => '0', + 'f.fk_soc' => '80LIMIT', + 'f.datec' => '2021-11-24', + 'f.datef' => '2021-11-24', + 'f.date_valid' => '2021-11-24', + 'f.paye' => '1', + 'f.remise_percent' => '0', + 'f.remise_absolue' => '0', + 'f.remise' => '0', + 'f.total_tva' => '21', + 'f.total_ht' => '100', + 'f.total_ttc' => '121', + 'f.fk_statut' => '1', + 'f.fk_user_modif' => '', + 'f.fk_user_valid' => '', + 'f.fk_user_closing' => '', + 'f.fk_facture_source' => '', + 'f.fk_projet' => '', + 'f.fk_account' => '', + 'f.fk_currency' => 'EUR', + 'f.fk_cond_reglement' => '30D', + 'f.fk_mode_reglement' => 'VIR', + 'f.date_lim_reglement' => '2021-12-24', + 'f.note_public' => '', + 'f.note_private' => '', + 'f.model_pdf' => 'crabe', + 'f.multicurrency_code' => 'EUR', + 'f.multicurrency_tx' => '1', + 'f.multicurrency_total_ht' => '100', + 'f.multicurrency_total_tva' => '21', + 'f.multicurrency_total_ttc' => '121' + ); + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); + $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref'); + $this->import_convertvalue_array[$r] = array( + 'f.fk_soc' => array( + 'rule' => 'fetchidfromref', + 'file' => '/societe/class/societe.class.php', + 'class' => 'Societe', + 'method' => 'fetch', + 'element' => 'ThirdParty' + ), + 'f.fk_projet' => array( + 'rule' => 'fetchidfromref', + 'file' => '/projet/class/project.class.php', + 'class' => 'Project', + 'method' => 'fetch', + 'element' => 'facture' + ), + 'f.fk_cond_reglement' => array( + 'rule' => 'fetchidfromcodeorlabel', + 'file' => '/compta/facture/class/paymentterm.class.php', + 'class' => 'PaymentTerm', + 'method' => 'fetch', + 'element' => 'c_payment_term' + ) + ); + + //Import Supplier Invoice Lines + $r++; + $this->import_code[$r] = $this->rights_class.'_'.$r; + $this->import_label[$r] = "InvoiceLine"; // Translation key + $this->import_icon[$r] = $this->picto; + $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facturedet', 'extra' => MAIN_DB_PREFIX.'facturedet_extrafields'); + $this->import_fields_array[$r] = array( + 'fd.fk_facture' => 'InvoiceRef*', + 'fd.fk_parent_line' => 'FacParentLine', + 'fd.fk_product' => 'IdProduct', + 'fd.label' => 'Label', + 'fd.description' => 'LineDescription*', + 'fd.vat_src_code' => 'Vat Source Code', + 'fd.tva_tx' => 'LineVATRate*', + // localtax1_tx + // localtax1_type + // localtax2_tx + // localtax2_type + 'fd.qty' => 'LineQty', + 'fd.remise_percent' => 'Reduc. (%)', + // remise + // fk_remise_except + // subprice + // price + 'fd.total_ht' => 'LineTotalHT', + 'fd.total_tva' => 'LineTotalVAT', + // total_localtax1 + // total_localtax2 + 'fd.total_ttc' => 'LineTotalTTC', + 'fd.product_type' => 'TypeOfLineServiceOrProduct', + 'fd.date_start' => 'Start Date', + 'fd.date_end' => 'End Date', + // info_bits + // buy_price_ht + // fk_product_fournisseur_price + // specia_code + // rang + // fk_contract_line + 'fd.fk_unit' => 'Unit', + // fk_code_ventilation + // situation_percent + // fk_prev_id + // fk_user_author + // fk_user_modif + // ref_ext + ); + if (!empty($conf->multicurrency->enabled)) { + $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency'; + $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate'; + $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; + $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; + $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; + } + // Add extra fields + $import_extrafield_sample = array(); + $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_det' AND entity IN (0, ".$conf->entity.")"; + $resql = $this->db->query($sql); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $fieldname = 'extra.'.$obj->name; + $fieldlabel = ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : ''); + $import_extrafield_sample[$fieldname] = $fieldlabel; + } + } + // End add extra fields + $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facturedet'); + $this->import_regex_array[$r] = array( + 'fd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product', + 'fd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency' + ); + $import_sample = array( + 'fd.fk_facture' => '(PROV00001)', + 'fd.fk_parent_line' => '', + 'fd.fk_product' => '', + 'fd.label' => '', + 'fd.description' => 'Test product', + 'fd.vat_src_code' => '', + 'fd.tva_tx' => '21', + // localtax1_tx + // localtax1_type + // localtax2_tx + // localtax2_type + 'fd.qty' => '1', + 'fd.remise_percent' => '0', + // remise + // fk_remise_except + // subprice + // price + 'fd.total_ht' => '100', + 'fd.total_tva' => '21', + // total_localtax1 + // total_localtax2 + 'fd.total_ttc' => '121', + 'fd.product_type' => '0', + 'fd.date_start' => '', + 'fd.date_end' => '', + // info_bits + // buy_price_ht + // fk_product_fournisseur_price + // specia_code + // rang + // fk_contract_line + 'fd.fk_unit' => '', + // fk_code_ventilation + // situation_percent + // fk_prev_id + // fk_user_author + // fk_user_modif + // ref_ext + 'fd.multicurrency_code' => 'EUR', + 'fd.multicurrency_tx' => '21', + 'fd.multicurrency_total_ht' => '100', + 'fd.multicurrency_total_tva' => '21', + 'fd.multicurrency_total_ttc' => '121' + ); + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); + $this->import_updatekeys_array[$r] = array( + 'fd.rowid' => 'Row Id', + 'fd.fk_facture' => 'Invoice Id' + ); + $this->import_convertvalue_array[$r] = array( + 'fd.fk_facture' => array( + 'rule' => 'fetchidfromref', + 'file' => '/compta/facture/class/facture.class.php', + 'class' => 'Facture', + 'method' => 'fetch', + 'element' => 'facture' + ), + 'fd.fk_projet' => array( + 'rule' => 'fetchidfromref', + 'file' => '/projet/class/project.class.php', + 'class' => 'Project', + 'method' => 'fetch', + 'element' => 'facture' + ), + ); + + // Exports //-------- $r = 1; From e58d783ced53ba4101bbeb4d7c1dd151abdeff54 Mon Sep 17 00:00:00 2001 From: Vincent Dieltiens Date: Thu, 6 Jan 2022 10:41:38 +0100 Subject: [PATCH 2/8] add comment to parameter --- htdocs/compta/facture/class/paymentterm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index 143f4bcf746..fd842e3485f 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -172,7 +172,7 @@ class PaymentTerm // extends CommonObject * Load object in memory from database * * @param int $id Id object - * @param string $code + * @param string $code Code object * @return int <0 if KO, >0 if OK */ public function fetch($id, $code = '') From a29aa48100535db440af5b2314c5e4421a48faea Mon Sep 17 00:00:00 2001 From: Abdelaziz MISBAH Date: Tue, 7 Jun 2022 13:11:30 +0100 Subject: [PATCH 3/8] Send Notification Without File when E-mail Template does'nt attach file When we create an Email Template that does'nt require main file to be attached, we still send notification with an attached file, eg: when we send a notification when validating proposal it send proposal with attached file with mention NOT VALIDATED. I added OR condition on checking pdf_path. --- htdocs/core/class/notify.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 452d066886e..e66b378ca38 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -615,7 +615,7 @@ class Notify $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output."/".$ref.".pdf"; - if (!dol_is_file($pdf_path)) { + if (!dol_is_file($pdf_path)||!$arraydefaultmessage->joinfiles) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { From 1cf8b3421f777155b71eb60152613a579dffc278 Mon Sep 17 00:00:00 2001 From: melina Date: Tue, 7 Jun 2022 17:46:17 +0200 Subject: [PATCH 4/8] add constant for freezone --- htdocs/takepos/invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3a55d82b8ad..3b0861956b7 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -585,7 +585,7 @@ if (empty($reshook)) { $localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr); - $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, '', '', 0, 100, '', null, 0); + $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', 0, 0, 0, '', getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') ? 'HT' : 'TTC', $number, 0, -1, 0, '', 0, 0, null, '', '', 0, 100, '', null, 0); $invoice->fetch($placeid); } From 14e7c5454ec0d983c1540b8b951b1fa737e3374c Mon Sep 17 00:00:00 2001 From: Abdelaziz MISBAH Date: Thu, 9 Jun 2022 11:47:34 +0100 Subject: [PATCH 5/8] FIX #21141 Update condition to check for attached file to E-mail Template Update condition to check for attached file to E-ail Template, initial Commit doesn't check for if null (may generate fatal error depending on context), now we check if is an object, before checking if we join files. --- htdocs/core/class/notify.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index e66b378ca38..92e0272c00c 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -615,7 +615,7 @@ class Notify $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output."/".$ref.".pdf"; - if (!dol_is_file($pdf_path)||!$arraydefaultmessage->joinfiles) { + if (!dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { From b57a9d589645a7f06891c129be7369d5968e948a Mon Sep 17 00:00:00 2001 From: Lenin Rivas <53640168+leninrivas@users.noreply.github.com> Date: Fri, 10 Jun 2022 05:58:01 -0500 Subject: [PATCH 6/8] Save usermodid to updatePercent --- htdocs/comm/action/class/actioncomm.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 19eb35376cd..831c64d2553 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2515,12 +2515,13 @@ class ActionComm extends CommonObject * @param int $percent The new percent value for the event * @return int 1 when update of the event was suscessfull, otherwise -1 */ - public function updatePercent($id, $percent) + public function updatePercent($id, $percent, $usermodid) { $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; $sql .= " SET percent = ".(int) $percent; + if ($usermodid > 0) $sql .= ", fk_user_mod = ".$usermodid; $sql .= " WHERE id = ".((int) $id); if ($this->db->query($sql)) { From 562e9998fd522b165e48f907b958dc5f83bb6e50 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 12 Jun 2022 13:22:55 +0200 Subject: [PATCH 7/8] Fix php 8 compatibility --- htdocs/core/boxes/box_members_last_modified.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_members_last_modified.php b/htdocs/core/boxes/box_members_last_modified.php index 6b4a033f1a2..91ce3c93c36 100644 --- a/htdocs/core/boxes/box_members_last_modified.php +++ b/htdocs/core/boxes/box_members_last_modified.php @@ -109,7 +109,7 @@ class box_members_last_modified extends ModeleBoxes while ($line < $num) { $objp = $this->db->fetch_object($result); $datec = $this->db->jdate($objp->datec); - $datem = $this->db->jdate($objp->tms); + $datem = $this->db->jdate($objp->datem); $memberstatic->lastname = $objp->lastname; $memberstatic->firstname = $objp->firstname; From 503a5cdc82713b86e425a89efc2ab61197991833 Mon Sep 17 00:00:00 2001 From: Lenin Rivas <53640168+leninrivas@users.noreply.github.com> Date: Sun, 12 Jun 2022 06:33:42 -0500 Subject: [PATCH 8/8] Add user who modified the percent --- htdocs/comm/action/class/actioncomm.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 831c64d2553..156d5573ae8 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2513,9 +2513,10 @@ class ActionComm extends CommonObject * * @param int $id The id of the event * @param int $percent The new percent value for the event + * @param int $usermodid The user who modified the percent * @return int 1 when update of the event was suscessfull, otherwise -1 */ - public function updatePercent($id, $percent, $usermodid) + public function updatePercent($id, $percent, $usermodid = 0) { $this->db->begin();