From 66a1aa9a864857b3f3102ef75ca3b4971c417ec8 Mon Sep 17 00:00:00 2001 From: Ahmad Jamaly Rabib Date: Mon, 5 Oct 2020 00:39:35 +0600 Subject: [PATCH] NEW ADDED IMPORT TOOL FOR SUPPLIER INVOICE Added supplier invoice import functionality in import module --- htdocs/core/modules/modFournisseur.class.php | 213 +++++++++++++++++-- htdocs/langs/en_US/bills.lang | 1 + 2 files changed, 196 insertions(+), 18 deletions(-) diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index b65c4fd956b..7d055082121 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2013-2015 Philippe Grand + * Copyright (C) 2020 Ahmad Jamaly Rabib * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -120,13 +121,13 @@ class modFournisseur extends DolibarrModules // Boxes $this->boxes = array( - 0=>array('file'=>'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton'=>'Home'), - 1=>array('file'=>'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton'=>'Home'), - 2=>array('file'=>'box_fournisseurs.php', 'enabledbydefaulton'=>'Home'), - 3=>array('file'=>'box_factures_fourn_imp.php', 'enabledbydefaulton'=>'Home'), - 4=>array('file'=>'box_factures_fourn.php', 'enabledbydefaulton'=>'Home'), - 5=>array('file'=>'box_supplier_orders.php', 'enabledbydefaulton'=>'Home'), - 6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'), + 0=>array('file'=>'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton'=>'Home'), + 1=>array('file'=>'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton'=>'Home'), + 2=>array('file'=>'box_fournisseurs.php', 'enabledbydefaulton'=>'Home'), + 3=>array('file'=>'box_factures_fourn_imp.php', 'enabledbydefaulton'=>'Home'), + 4=>array('file'=>'box_factures_fourn.php', 'enabledbydefaulton'=>'Home'), + 5=>array('file'=>'box_supplier_orders.php', 'enabledbydefaulton'=>'Home'), + 6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'), ); // Permissions @@ -190,12 +191,12 @@ class modFournisseur extends DolibarrModules $this->rights[$r][5] = 'receptionner'; $r++; - $this->rights[$r][0] = 1189; - $this->rights[$r][1] = 'Check/Uncheck a supplier order reception'; - $this->rights[$r][2] = 'w'; - $this->rights[$r][3] = 0; - $this->rights[$r][4] = 'commande_advance'; - $this->rights[$r][5] = 'check'; + $this->rights[$r][0] = 1189; + $this->rights[$r][1] = 'Check/Uncheck a supplier order reception'; + $this->rights[$r][2] = 'w'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'commande_advance'; + $this->rights[$r][5] = 'check'; $r++; $this->rights[$r][0] = 1188; @@ -273,9 +274,9 @@ class modFournisseur extends DolibarrModules $this->rights[$r][5] = 'export'; - // Menus - //------- - $this->menu = 1; // This module add menu entries. They are coded into menu manager. + // Menus + //------- + $this->menu = 1; // This module add menu entries. They are coded into menu manager. // Exports @@ -459,7 +460,7 @@ class modFournisseur extends DolibarrModules 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company', 'f.rowid'=>"invoice", 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.total_ht'=>"invoice", 'f.total_ttc'=>"invoice", 'f.total_tva'=>"invoice", 'f.paye'=>"invoice", 'f.fk_statut'=>'invoice', 'f.note_public'=>"invoice", 'p.rowid'=>'payment', 'pf.amount'=>'payment', - 'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'); + 'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'); $this->export_dependencies_array[$r] = array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them // Add extra fields object $sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")"; @@ -508,7 +509,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid'; $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid'; - $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')'; + $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')'; if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; // Order @@ -650,6 +651,182 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande'; $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')'; if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + + //Import Supplier Invoice + //-------- + $r=0; + + $r++; + $this->import_code[$r] = $this->rights_class . '_' . $r; + $this->import_label[$r] = "Supplier Invoice"; // Translation key + $this->import_icon[$r] = $this->picto; + $this->import_entities_array[$r] = []; // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r] = ['f' => MAIN_DB_PREFIX . 'facture_fourn', 'extra' => MAIN_DB_PREFIX . 'facture_fourn_extrafields']; + $this->import_tables_creator_array[$r] = ['f' => 'fk_user_author']; // Fields to store import user id + $this->import_fields_array[$r] = [ + 'f.ref' => 'InvoiceRef*', + 'f.ref_supplier' => 'RefSupplier', + 'f.type' => 'Type*', + 'f.fk_soc' => 'Supplier/Vendor*', + 'f.datec' => 'InvoiceDateCreation', + 'f.datef' => 'DateInvoice', + 'f.date_lim_reglement' => 'DateMaxPayment', + 'f.total_ht' => 'TotalHT', + 'f.total_ttc' => 'TotalTTC', + 'f.total_tva' => 'TotalVAT', + 'f.paye' => 'InvoicePaid', + 'f.fk_statut' => 'InvoiceStatus', + 'f.fk_user_modif' => 'Modifier Id', + 'f.fk_user_valid' => 'Validator Id', + 'f.fk_facture_source' => 'Invoice Source Id', + 'f.fk_projet' => 'Project Id', + 'f.fk_account' => 'Bank Account*', + 'f.note_public' => 'InvoiceNote', + 'f.note_private' => 'NotePrivate', + 'f.fk_cond_reglement' => 'Payment Condition', + 'f.fk_mode_reglement' => 'Payment Mode', + 'f.model_pdf' => 'Model', + 'f.date_valid' => 'Validation Date' + ]; + 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 = []; + $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE elementtype = 'facture_fourn' 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] = ['extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'facture_fourn']; + $this->import_regex_array[$r] = ['f.ref' => '(SI\d{4}-\d{4}|PROV.{1,32}$)', 'f.multicurrency_code' => 'code@' . MAIN_DB_PREFIX . 'multicurrency']; + $import_sample = [ + 'f.ref' => '(PROV001)', + 'f.ref_supplier' => 'Supplier1', + 'f.type' => '0', + 'f.fk_soc' => 'Vendor1', + 'f.datec' => '2021-01-01', + 'f.datef' => '', + 'f.date_lim_reglement' => '2021-01-30', + 'f.total_ht' => '1000', + 'f.total_ttc' => '1000', + 'f.total_tva' => '0', + 'f.paye' => '0', + 'f.fk_statut' => '0', + 'f.fk_user_modif' => '', + 'f.fk_user_valid' => '', + 'f.fk_facture_source' => '', + 'f.fk_projet' => '', + 'f.fk_account' => 'BANK1', + 'f.note_public' => 'Note: ', + 'f.note_private' => '', + 'f.fk_cond_reglement' => '1', + 'f.fk_mode_reglement' => '2', + 'f.model_pdf' => 'crab', + 'f.date_valid' => '', + 'f.multicurrency_code' => 'USD', + 'f.multicurrency_tx' => '1', + 'f.multicurrency_total_ht' => '1000', + 'f.multicurrency_total_tva' => '0', + 'f.multicurrency_total_ttc' => '1000' + ]; + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); + $this->import_updatekeys_array[$r] = ['f.ref' => 'Ref']; + $this->import_convertvalue_array[$r] = [ + //'c.ref'=>array('rule'=>'getrefifauto'), + 'f.fk_soc' => ['rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'], + 'f.fk_account' => ['rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'], + ]; + + //Import Supplier Invoice Lines + $r++; + $this->import_code[$r] = $this->rights_class.'_'.$r; + $this->import_label[$r] = "Supplier Invoice Lines"; // Translation key + $this->import_icon[$r] = $this->picto; + $this->import_entities_array[$r] = []; // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r] = ['fd' => MAIN_DB_PREFIX . 'facture_fourn_det', 'extra' => MAIN_DB_PREFIX . 'facture_fourn_det_extrafields']; + $this->import_fields_array[$r] = [ + 'fd.fk_facture_fourn' => 'InvoiceRef*', + 'fd.fk_parent_line' => 'FacParentLine', + 'fd.fk_product' => 'IdProduct', + 'fd.label' => 'Label', + 'fd.description' => 'LineDescription', + 'fd.pu_ht' => 'PriceUHT', + 'fd.pu_ttc' => 'PriceUTTC', + 'fd.qty' => 'LineQty', + 'fd.remise_percent' => 'Reduc.', + 'fd.vat_src_code' => 'Vat Source Code', + 'fd.product_type' => 'TypeOfLineServiceOrProduct', + 'fd.tva_tx' => 'LineVATRate', + 'fd.total_ht' => 'LineTotalHT', + 'fd.tva' => 'LineTotalVAT', + 'fd.total_ttc' => 'LineTotalTTC', + 'fd.date_start' => 'Start Date', + 'fd.date_end' => 'End Date', + 'fd.fk_unit' => 'Unit' + ]; + 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 = []; + $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE elementtype = 'facture_fourn_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] = ['extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'facture_fourn_det']; + $this->import_regex_array[$r] = ['fd.product_type' => '[0|1]$', 'fd.fk_product' => 'rowid@' . MAIN_DB_PREFIX . 'product', 'fd.multicurrency_code' => 'code@' . MAIN_DB_PREFIX . 'multicurrency']; + $import_sample = [ + 'fd.fk_facture_fourn' => '(PROV001)', + 'fd.fk_parent_line' => '', + 'fd.fk_product' => '', + 'fd.label' => '', + 'fd.description' => 'Test Product', + 'fd.pu_ht' => '50000', + 'fd.pu_ttc' => '50000', + 'fd.qty' => '1', + 'fd.remise_percent' => '0', + 'fd.vat_src_code' => '', + 'fd.product_type' => '0', + 'fd.tva_tx' => '0', + 'fd.total_ht' => '50000', + 'fd.tva' => '0', + 'fd.total_ttc' => '50000', + 'fd.date_start' => '', + 'fd.date_end' => '', + 'fd.fk_unit' => '', + 'fd.multicurrency_code' => 'USD', + 'fd.multicurrency_tx' => '0', + 'fd.multicurrency_total_ht' => '50000', + 'fd.multicurrency_total_tva' => '0', + 'fd.multicurrency_total_ttc' => '50000' + ]; + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); + $this->import_updatekeys_array[$r] = ['fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id']; + $this->import_convertvalue_array[$r] = [ + 'fd.fk_facture_fourn' => ['rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'], + ]; } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index d5d418affc6..9c918bd0a15 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -575,3 +575,4 @@ BILL_SUPPLIER_DELETEInDolibarr=Supplier invoice deleted UnitPriceXQtyLessDiscount=Unit price x Qty - Discount CustomersInvoicesArea=Customer billing area SupplierInvoicesArea=Supplier billing area +FacParentLine=Invoice Line Parent