From 0b35a0729010055a3621b373cf2cd2d1df5f4ff6 Mon Sep 17 00:00:00 2001 From: Ahmad Jamaly Rabib Date: Thu, 1 Oct 2020 11:52:56 +0600 Subject: [PATCH] NEW ADDED IMPORT TOOL FOR PROPOSAL MODULE Added proposal import functionality in import module --- htdocs/core/modules/modPropale.class.php | 169 +++++++++++++++++++++++ htdocs/imports/class/import.class.php | 3 + htdocs/langs/am_ET/propal.lang | 4 + htdocs/langs/de_DE/propal.lang | 4 + htdocs/langs/en_US/main.lang | 3 +- htdocs/langs/en_US/propal.lang | 5 + htdocs/langs/fr_FR/propal.lang | 4 + htdocs/langs/ja_JP/propal.lang | 4 + htdocs/langs/ko_KR/propal.lang | 4 + htdocs/langs/vi_VN/propal.lang | 4 + htdocs/langs/zh_CN/propal.lang | 4 + 11 files changed, 207 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index 007e92e4277..4da02808251 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -5,6 +5,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Juanjo Menent + * 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 @@ -254,6 +255,174 @@ class modPropale extends DolibarrModules $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('propal').')'; if (!$user->rights->societe->client->voir) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + + // Imports + //-------- + $r = 0; + + $r++; + $this->import_code[$r] = $this->rights_class.'_'.$r; + $this->import_label[$r] = 'Proposals'; // 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] = ['c' => MAIN_DB_PREFIX . 'propal', 'extra' => MAIN_DB_PREFIX . 'propal_extrafields']; + $this->import_tables_creator_array[$r] = ['c'=>'fk_user_author']; // Fields to store import user id + $this->import_fields_array[$r] = [ + 'c.ref' => 'Document Ref*', + 'c.ref_client' => 'RefCustomer', + 'c.fk_soc' => 'ThirdPartyName*', + 'c.datec' => 'DateCreation', + 'c.datep' => 'DatePropal', + 'c.fin_validite' => 'DateEndPropal', + 'c.remise_percent' => 'GlobalDiscount', + 'c.total_ht' => 'TotalHT', + 'c.total' => 'TotalTTC', + 'c.fk_statut' => 'Status*', + 'c.note_public' => 'Note', + 'c.date_livraison' => 'DeliveryDate', + 'c.fk_user_valid' => 'ValidatedById' + ]; + if (! empty($conf->multicurrency->enabled)) { + $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency'; + $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate'; + $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; + $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; + $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; + } + // Add extra fields + $import_extrafield_sample = []; + $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE elementtype = 'propal' 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 . 'propal']; + $this->import_regex_array[$r] = ['c.ref' => '[^ ]']; + $import_sample = [ + 'c.ref' => 'PROV0077', + 'c.ref_client' => 'Client1', + 'c.fk_soc' => 'MyBigCompany', + 'c.datec' => '2020-01-01', + 'c.datep' => '2020-01-01', + 'c.fin_validite' => '2020-01-01', + 'c.remise_percent' => '', + 'c.total_ht' => '0', + 'c.total' => '0', + 'c.fk_statut' => '1', + 'c.note_public' => '', + 'c.date_livraison' => '2020-01-01', + 'c.fk_user_valid' => '1', + 'c.multicurrency_code' => '', + 'c.multicurrency_tx' => '1', + 'c.multicurrency_total_ht' => '0', + 'c.multicurrency_total_tva' => '0', + 'c.multicurrency_total_ttc' => '0' + ]; + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); + $this->import_updatekeys_array[$r] = ['c.ref'=>'Ref']; + $this->import_convertvalue_array[$r] = [ + 'c.fk_soc' => [ + 'rule' => 'fetchidfromref', + 'file' => '/societe/class/societe.class.php', + 'class' => 'Societe', + 'method' => 'fetch', + 'element' => 'ThirdParty' + ] + ]; + + //Import Proposal Lines + $r++; + $this->import_code[$r] = $this->rights_class.'line_'.$r; + $this->import_label[$r] = "ProposalLine"; // 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] = [ + 'cd' => MAIN_DB_PREFIX . 'propaldet', + 'extra' => MAIN_DB_PREFIX . 'propaldet_extrafields' + ]; + $this->import_fields_array[$r] = [ + 'cd.fk_propal' => 'Document Ref*', + 'cd.fk_parent_line' => 'PrParentLine', + 'cd.fk_product' => 'IdProduct', + 'cd.label' => 'Label', + 'cd.description' => 'LineDescription', + 'cd.product_type' => 'TypeOfLineServiceOrProduct', + 'cd.tva_tx' => 'LineVATRate', + 'cd.qty' => 'LineQty', + 'cd.remise_percent' => 'Reduc. Percent', + 'cd.remise' => 'Reduc.', + 'cd.price' => 'Price', + 'cd.subprice' => 'Sub Price', + 'cd.total_ht' => 'LineTotalHT', + 'cd.total_tva' => 'LineTotalVAT', + 'cd.total_ttc' => 'LineTotalTTC', + 'cd.date_start' => 'Start Date', + 'cd.date_end' => 'End Date', + 'cd.buy_price_ht' => 'LineBuyPriceHT' + ]; + if (! empty($conf->multicurrency->enabled)) { + $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency'; + $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate'; + $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; + $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; + $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; + } + // Add extra fields + $import_extrafield_sample = []; + $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'propaldet' 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 . 'propaldet']; + $this->import_regex_array[$r] = ['cd.product_type' => '[0|1]$']; + $import_sample = [ + 'cd.fk_propal' => 'PROV(0001)', + 'cd.fk_parent_line' => '', + 'cd.fk_product' => '', + 'cd.label' => '', + 'cd.description' => 'Line description', + 'cd.product_type' => '1', + 'cd.tva_tx' => '0', + 'cd.qty' => '2', + 'cd.remise_percent' => '0', + 'cd.remise' => '0', + 'cd.price' => '', + 'cd.subprice' => '5000', + 'cd.total_ht' => '10000', + 'cd.total_tva' => '0', + 'cd.total_ttc' => '10100', + 'cd.date_start' => '', + 'cd.date_end' => '', + 'cd.buy_price_ht' => '7000', + 'cd.multicurrency_code' => 'JPY', + 'cd.multicurrency_tx' => '1', + 'cd.multicurrency_total_ht' => '10000', + 'cd.multicurrency_total_tva' => '0', + 'cd.multicurrency_total_ttc' => '10100' + ]; + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); + $this->import_updatekeys_array[$r] = ['cd.fk_propal' => 'Quotation Id', 'cd.fk_product' => 'Product Id']; + $this->import_convertvalue_array[$r] = [ + 'cd.fk_propal' => [ + 'rule'=>'fetchidfromref', + 'file'=>'/comm/propal/class/propal.class.php', + 'class'=>'Propal', + 'method'=>'fetch' + ] + ]; } diff --git a/htdocs/imports/class/import.class.php b/htdocs/imports/class/import.class.php index 72d1eb16f66..f3e3d988c5b 100644 --- a/htdocs/imports/class/import.class.php +++ b/htdocs/imports/class/import.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2016 Raphaël Doursenaud + * 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 @@ -101,6 +102,8 @@ class Import // Defined if module is enabled $enabled = true; $part = strtolower(preg_replace('/^mod/i', '', $modulename)); + // Adds condition for propal module + if ($part === 'propale') $part = 'propal'; if (empty($conf->$part->enabled)) $enabled = false; if (empty($enabled)) continue; diff --git a/htdocs/langs/am_ET/propal.lang b/htdocs/langs/am_ET/propal.lang index 273996ab1b1..95085002f66 100644 --- a/htdocs/langs/am_ET/propal.lang +++ b/htdocs/langs/am_ET/propal.lang @@ -85,3 +85,7 @@ ProposalCustomerSignature=Written acceptance, company stamp, date and signature ProposalsStatisticsSuppliers=Vendor proposals statistics CaseFollowedBy=Case followed by SignedOnly=Signed only +IdProposal=Proposal ID +IdProduct=Product ID +PrParentLine=Proposal Parent Line +LineBuyPriceHT=Buy Price Amount net of tax for line diff --git a/htdocs/langs/de_DE/propal.lang b/htdocs/langs/de_DE/propal.lang index 78e3e09a746..0956cf4900f 100644 --- a/htdocs/langs/de_DE/propal.lang +++ b/htdocs/langs/de_DE/propal.lang @@ -85,3 +85,7 @@ ProposalCustomerSignature=Bei Beauftragung: Name in Klarschrift, Ort, Datum, Unt ProposalsStatisticsSuppliers=Statistik Lieferantenanfragen CaseFollowedBy=Fall gefolgt von SignedOnly=nur signiert +IdProposal=Angebots-ID +IdProduct=Produkt ID +PrParentLine=Übergeordnete Zeile des Vorschlags +LineBuyPriceHT=Kaufpreis Betrag abzüglich Steuern für Linie diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 0289b381b23..427a5a80d45 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -371,6 +371,7 @@ MulticurrencyPaymentAmount=Payment amount, original currency MulticurrencyAmountHT=Amount (excl. tax), original currency MulticurrencyAmountTTC=Amount (inc. of tax), original currency MulticurrencyAmountVAT=Amount tax, original currency +MulticurrencySubPrice=Amount sub price multi currency AmountLT1=Amount tax 2 AmountLT2=Amount tax 3 AmountLT1ES=Amount RE @@ -1094,4 +1095,4 @@ PublicVendorName=Public name of vendor DateOfBirth=Date of birth SecurityTokenHasExpiredSoActionHasBeenCanceledPleaseRetry=Security token has expired, so action has been canceled. Please try again. UpToDate=Up-to-date -OutOfDate=Out-of-date \ No newline at end of file +OutOfDate=Out-of-date diff --git a/htdocs/langs/en_US/propal.lang b/htdocs/langs/en_US/propal.lang index c68574d9ae2..557df2f840f 100644 --- a/htdocs/langs/en_US/propal.lang +++ b/htdocs/langs/en_US/propal.lang @@ -84,3 +84,8 @@ ProposalCustomerSignature=Written acceptance, company stamp, date and signature ProposalsStatisticsSuppliers=Vendor proposals statistics CaseFollowedBy=Case followed by SignedOnly=Signed only +IdProposal=Proposal ID +IdProduct=Product ID +PrParentLine=Proposal Parent Line +LineBuyPriceHT=Buy Price Amount net of tax for line + diff --git a/htdocs/langs/fr_FR/propal.lang b/htdocs/langs/fr_FR/propal.lang index 03981e2b17d..64199c5248d 100644 --- a/htdocs/langs/fr_FR/propal.lang +++ b/htdocs/langs/fr_FR/propal.lang @@ -98,3 +98,7 @@ ConfirmMassValidationQuestion = Voulez-vous confirmer la validation des devis br ConfirmMassSignatureQuestion = Voulez-vous confirmer la signature des devis ouvert selectionnés ? PropNoProductOrService = devis ne contient pas de produits ni de services PropsNoProductOrService = devis ne contiennent pas de produits ni de services +IdProposal=ID de proposition +IdProduct=ID produit +PrParentLine=Ligne parent de proposition +LineBuyPriceHT=Prix ​​d'achat Montant net de taxe pour la ligne diff --git a/htdocs/langs/ja_JP/propal.lang b/htdocs/langs/ja_JP/propal.lang index d2065e007a3..373ac4a2ce2 100644 --- a/htdocs/langs/ja_JP/propal.lang +++ b/htdocs/langs/ja_JP/propal.lang @@ -85,3 +85,7 @@ ProposalCustomerSignature=承諾書、会社印、日付、署名 ProposalsStatisticsSuppliers=Vendor proposals statistics CaseFollowedBy=Case followed by SignedOnly=Signed only +IdProposal=提案番号 +IdProduct=製品番号 +PrParentLine=提案親ライン +LineBuyPriceHT=購入価格ラインの税控除後の金額 diff --git a/htdocs/langs/ko_KR/propal.lang b/htdocs/langs/ko_KR/propal.lang index 93708eb0955..26a86464f91 100644 --- a/htdocs/langs/ko_KR/propal.lang +++ b/htdocs/langs/ko_KR/propal.lang @@ -85,3 +85,7 @@ ProposalCustomerSignature=Written acceptance, company stamp, date and signature ProposalsStatisticsSuppliers=Vendor proposals statistics CaseFollowedBy=Case followed by SignedOnly=Signed only +IdProposal=Proposal ID +IdProduct=Product ID +PrParentLine=Proposal Parent Line +LineBuyPriceHT=Buy Price Amount net of tax for line diff --git a/htdocs/langs/vi_VN/propal.lang b/htdocs/langs/vi_VN/propal.lang index 2a99f2a5577..a9e808d9f5a 100644 --- a/htdocs/langs/vi_VN/propal.lang +++ b/htdocs/langs/vi_VN/propal.lang @@ -85,3 +85,7 @@ ProposalCustomerSignature=Văn bản chấp nhận, dấu công ty, ngày và ch ProposalsStatisticsSuppliers=Thống kê đề xuất nhà cung cấp CaseFollowedBy=Theo bởi trường hợp SignedOnly=Signed only +IdProposal=ID đề xuất +IdProduct=ID sản phẩm +PrParentLine=Dòng mẹ đề xuất +LineBuyPriceHT=Giá mua Số lượng ròng của thuế cho dòng diff --git a/htdocs/langs/zh_CN/propal.lang b/htdocs/langs/zh_CN/propal.lang index 2c782854e14..79d10f5e2ba 100644 --- a/htdocs/langs/zh_CN/propal.lang +++ b/htdocs/langs/zh_CN/propal.lang @@ -85,3 +85,7 @@ ProposalCustomerSignature=书面接受,公司盖章,日期和签名 ProposalsStatisticsSuppliers=Vendor proposals statistics CaseFollowedBy=Case followed by SignedOnly=Signed only +IdProposal=提案编号 +IdProduct=产品编号 +PrParentLine=提案父行 +LineBuyPriceHT=购买价格扣除税额