Merge pull request #14920 from rabib-metroworks/import-vendor-invoice

NEW Can import Supplier invoice
This commit is contained in:
Laurent Destailleur 2020-10-05 16:44:49 +02:00 committed by GitHub
commit 23f1137c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 196 additions and 18 deletions

View File

@ -4,6 +4,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2015 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2013-2015 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2020 Ahmad Jamaly Rabib <rabib@metroworks.co.jp>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -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] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
$this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')'; $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; 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'],
];
} }

View File

@ -575,3 +575,4 @@ BILL_SUPPLIER_DELETEInDolibarr=Supplier invoice deleted
UnitPriceXQtyLessDiscount=Unit price x Qty - Discount UnitPriceXQtyLessDiscount=Unit price x Qty - Discount
CustomersInvoicesArea=Customer billing area CustomersInvoicesArea=Customer billing area
SupplierInvoicesArea=Supplier billing area SupplierInvoicesArea=Supplier billing area
FacParentLine=Invoice Line Parent