| Conditions | 21 |
| Paths | 4608 |
| Total Lines | 426 |
| Code Lines | 336 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 49 | public function __construct($db) |
||
| 50 | { |
||
| 51 | global $conf, $user; |
||
| 52 | |||
| 53 | $this->db = $db; |
||
| 54 | $this->numero = 20; |
||
| 55 | |||
| 56 | $this->family = "crm"; |
||
| 57 | $this->module_position = '10'; |
||
| 58 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
||
| 59 | $this->name = preg_replace('/^mod/i', '', get_only_class($this)); |
||
| 60 | $this->description = "Gestion des propositions commerciales"; |
||
| 61 | |||
| 62 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
||
| 63 | $this->version = 'dolibarr'; |
||
| 64 | |||
| 65 | $this->const_name = 'MAIN_MODULE_' . static::getNameOf($this->name); // strtoupper($this->name); |
||
| 66 | $this->picto = 'propal'; |
||
| 67 | |||
| 68 | // Data directories to create when module is enabled |
||
| 69 | $this->dirs = array("/propale/temp"); |
||
| 70 | |||
| 71 | // Dependencies |
||
| 72 | $this->hidden = false; // A condition to hide module |
||
| 73 | $this->depends = array("modSociete"); // List of module class names as string that must be enabled if this module is enabled |
||
| 74 | $this->requiredby = array(); // List of module ids to disable if this one is disabled |
||
| 75 | $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
||
| 76 | $this->phpmin = array(7, 0); // Minimum version of PHP required by module |
||
| 77 | $this->config_page_url = array("propal.php"); |
||
| 78 | $this->langfiles = array("propal", "bills", "companies", "deliveries", "products"); |
||
| 79 | |||
| 80 | // Constants |
||
| 81 | $this->const = array(); |
||
| 82 | $r = 0; |
||
| 83 | |||
| 84 | $this->const[$r][0] = "PROPALE_ADDON_PDF"; |
||
| 85 | $this->const[$r][1] = "chaine"; |
||
| 86 | $this->const[$r][2] = "cyan"; |
||
| 87 | $this->const[$r][3] = 'Name of the proposal generation manager in PDF format'; |
||
| 88 | $this->const[$r][4] = 0; |
||
| 89 | $r++; |
||
| 90 | |||
| 91 | $this->const[$r][0] = "PROPALE_ADDON"; |
||
| 92 | $this->const[$r][1] = "chaine"; |
||
| 93 | $this->const[$r][2] = "mod_propale_marbre"; |
||
| 94 | $this->const[$r][3] = 'Name of proposal numbering manager'; |
||
| 95 | $this->const[$r][4] = 0; |
||
| 96 | $r++; |
||
| 97 | |||
| 98 | $this->const[$r][0] = "PROPALE_VALIDITY_DURATION"; |
||
| 99 | $this->const[$r][1] = "chaine"; |
||
| 100 | $this->const[$r][2] = "15"; |
||
| 101 | $this->const[$r][3] = 'Duration of validity of business proposals'; |
||
| 102 | $this->const[$r][4] = 0; |
||
| 103 | $r++; |
||
| 104 | |||
| 105 | $this->const[$r][0] = "PROPALE_ADDON_PDF_ODT_PATH"; |
||
| 106 | $this->const[$r][1] = "chaine"; |
||
| 107 | $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/proposals"; |
||
| 108 | $this->const[$r][3] = ""; |
||
| 109 | $this->const[$r][4] = 0; |
||
| 110 | $r++; |
||
| 111 | |||
| 112 | $this->const[$r][0] = "PROPOSAL_ALLOW_ONLINESIGN"; |
||
| 113 | $this->const[$r][1] = "chaine"; |
||
| 114 | $this->const[$r][2] = "1"; |
||
| 115 | $this->const[$r][3] = ""; |
||
| 116 | $this->const[$r][4] = 0; |
||
| 117 | $r++; |
||
| 118 | |||
| 119 | /*$this->const[$r][0] = "PROPALE_DRAFT_WATERMARK"; |
||
| 120 | $this->const[$r][2] = "__(Draft)__"; |
||
| 121 | $this->const[$r][3] = 'Watermark to show on draft proposals'; |
||
| 122 | $this->const[$r][4] = 0; |
||
| 123 | $r++;*/ |
||
| 124 | |||
| 125 | // Boxes |
||
| 126 | $this->boxes = array( |
||
| 127 | 0 => array('file' => 'box_graph_propales_permonth.php', 'enabledbydefaulton' => 'Home'), |
||
| 128 | 1 => array('file' => 'box_propales.php', 'enabledbydefaulton' => 'Home'), |
||
| 129 | ); |
||
| 130 | |||
| 131 | // Permissions |
||
| 132 | $this->rights = array(); |
||
| 133 | $this->rights_class = 'propale'; |
||
| 134 | $r = 0; |
||
| 135 | |||
| 136 | $r++; |
||
| 137 | $this->rights[$r][0] = 21; // id de la permission |
||
| 138 | $this->rights[$r][1] = 'Read commercial proposals'; // libelle de la permission |
||
| 139 | $this->rights[$r][2] = 'r'; // type de la permission (deprecated) |
||
| 140 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 141 | $this->rights[$r][4] = 'lire'; |
||
| 142 | |||
| 143 | $r++; |
||
| 144 | $this->rights[$r][0] = 22; // id de la permission |
||
| 145 | $this->rights[$r][1] = 'Create and update commercial proposals'; // libelle de la permission |
||
| 146 | $this->rights[$r][2] = 'w'; // type de la permission (deprecated) |
||
| 147 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 148 | $this->rights[$r][4] = 'creer'; |
||
| 149 | |||
| 150 | $r++; |
||
| 151 | $this->rights[$r][0] = 24; // id de la permission |
||
| 152 | $this->rights[$r][1] = 'Validate commercial proposals'; // Validate proposal |
||
| 153 | $this->rights[$r][2] = 'd'; // type de la permission (deprecated) |
||
| 154 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 155 | $this->rights[$r][4] = 'propal_advance'; |
||
| 156 | $this->rights[$r][5] = 'validate'; |
||
| 157 | |||
| 158 | $r++; |
||
| 159 | $this->rights[$r][0] = 25; // id de la permission |
||
| 160 | $this->rights[$r][1] = 'Send commercial proposals to customers'; // libelle de la permission |
||
| 161 | $this->rights[$r][2] = 'd'; // type de la permission (deprecated) |
||
| 162 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 163 | $this->rights[$r][4] = 'propal_advance'; |
||
| 164 | $this->rights[$r][5] = 'send'; |
||
| 165 | |||
| 166 | $r++; |
||
| 167 | $this->rights[$r][0] = 26; // id de la permission |
||
| 168 | $this->rights[$r][1] = 'Close commercial proposals'; // Set proposal to signed or refused |
||
| 169 | $this->rights[$r][2] = 'd'; // type de la permission (deprecated) |
||
| 170 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 171 | $this->rights[$r][4] = 'propal_advance'; |
||
| 172 | $this->rights[$r][5] = 'close'; |
||
| 173 | |||
| 174 | $r++; |
||
| 175 | $this->rights[$r][0] = 27; // id de la permission |
||
| 176 | $this->rights[$r][1] = 'Delete commercial proposals'; // libelle de la permission |
||
| 177 | $this->rights[$r][2] = 'd'; // type de la permission (deprecated) |
||
| 178 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 179 | $this->rights[$r][4] = 'supprimer'; |
||
| 180 | |||
| 181 | $r++; |
||
| 182 | $this->rights[$r][0] = 28; // id de la permission |
||
| 183 | $this->rights[$r][1] = 'Exporting commercial proposals and attributes'; // libelle de la permission |
||
| 184 | $this->rights[$r][2] = 'r'; // type de la permission (deprecated) |
||
| 185 | $this->rights[$r][3] = 0; // La permission est-elle une permission par default |
||
| 186 | $this->rights[$r][4] = 'export'; |
||
| 187 | |||
| 188 | |||
| 189 | // Menus |
||
| 190 | //------- |
||
| 191 | $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
||
| 192 | |||
| 193 | |||
| 194 | // Exports |
||
| 195 | //-------- |
||
| 196 | $r = 0; |
||
| 197 | |||
| 198 | $r++; |
||
| 199 | $this->export_code[$r] = $this->rights_class . '_' . $r; |
||
| 200 | $this->export_label[$r] = 'ProposalsAndProposalsLines'; // Translation key (used only if key ExportDataset_xxx_z not found) |
||
| 201 | $this->export_permission[$r] = array(array("propale", "export")); |
||
| 202 | $this->export_fields_array[$r] = array( |
||
| 203 | 's.rowid' => "IdCompany", 's.nom' => 'CompanyName', 'ps.nom' => 'ParentCompany', 's.code_client' => 'CustomerCode', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town', 'co.code' => 'CountryCode', 's.phone' => 'Phone', |
||
| 204 | 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 'c.rowid' => "Id", 'c.ref' => "Ref", 'c.ref_client' => "RefCustomer", |
||
| 205 | 'c.fk_soc' => "IdCompany", 'c.datec' => "DateCreation", 'c.datep' => "DatePropal", 'c.fin_validite' => "DateEndPropal", |
||
| 206 | 'c.total_ht' => "TotalHT", 'c.total_ttc' => "TotalTTC", |
||
| 207 | 'cir.label' => 'Source', |
||
| 208 | ); |
||
| 209 | if (isModEnabled("multicurrency")) { |
||
| 210 | $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency'; |
||
| 211 | $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate'; |
||
| 212 | $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; |
||
| 213 | $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; |
||
| 214 | $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; |
||
| 215 | } |
||
| 216 | $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array( |
||
| 217 | 'c.fk_statut' => 'Status', 'c.note_public' => "NotePublic", 'c.note_private' => "NotePrivate", 'c.date_livraison' => 'DeliveryDate', |
||
| 218 | 'c.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin', |
||
| 219 | 'c.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin')); |
||
| 220 | if (isModEnabled("project")) { |
||
| 221 | $this->export_fields_array[$r]['pj.ref'] = 'ProjectRef'; |
||
| 222 | } |
||
| 223 | $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array( |
||
| 224 | 'cd.rowid' => 'LineId', 'cd.description' => "LineDescription", 'cd.product_type' => 'TypeOfLineServiceOrProduct', |
||
| 225 | 'cd.tva_tx' => "LineVATRate", 'cd.qty' => "LineQty", 'cd.total_ht' => "LineTotalHT", 'cd.total_tva' => "LineTotalVAT", 'cd.total_ttc' => "LineTotalTTC", |
||
| 226 | )); |
||
| 227 | $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array( |
||
| 228 | 'p.rowid' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel' |
||
| 229 | )); |
||
| 230 | // Add multicompany field |
||
| 231 | if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) { |
||
| 232 | $nbofallowedentities = count(explode(',', getEntity('propal'))); |
||
| 233 | if (isModEnabled('multicompany') && $nbofallowedentities > 1) { |
||
| 234 | $this->export_fields_array[$r]['c.entity'] = 'Entity'; |
||
| 235 | } |
||
| 236 | } |
||
| 237 | //$this->export_TypeFields_array[$r]=array( |
||
| 238 | // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text', |
||
| 239 | // 's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.datec'=>"Date",'c.datep'=>"Date", |
||
| 240 | // 'c.fin_validite'=>"Date",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.note_private'=>"Text", |
||
| 241 | // 'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric", |
||
| 242 | // 'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text' |
||
| 243 | //); |
||
| 244 | $this->export_TypeFields_array[$r] = array( |
||
| 245 | 's.nom' => 'Text', 'ps.nom' => 'Text', 's.code_client' => 'Text', 's.address' => 'Text', 's.zip' => 'Text', 's.town' => 'Text', 'co.code' => 'Text', 's.phone' => 'Text', 's.siren' => 'Text', 's.siret' => 'Text', |
||
| 246 | 's.ape' => 'Text', 's.idprof4' => 'Text', 'c.ref' => "Text", 'c.ref_client' => "Text", 'c.datec' => "Date", 'c.datep' => "Date", 'c.fin_validite' => "Date", |
||
| 247 | 'c.total_ht' => "Numeric", 'c.total_ttc' => "Numeric", 'c.fk_statut' => 'Status', 'c.note_public' => "Text", 'c.note_private' => "Text", 'c.date_livraison' => 'Date', |
||
| 248 | 'pj.ref' => 'Text', 'cd.description' => "Text", 'cd.product_type' => 'Boolean', 'cd.tva_tx' => "Numeric", 'cd.qty' => "Numeric", 'cd.total_ht' => "Numeric", |
||
| 249 | 'cd.total_tva' => "Numeric", 'cd.total_ttc' => "Numeric", 'p.ref' => 'Text', 'p.label' => 'Text', |
||
| 250 | 'c.entity' => 'List:entity:label:rowid', |
||
| 251 | 'cir.label' => 'Text', |
||
| 252 | ); |
||
| 253 | $this->export_entities_array[$r] = array( |
||
| 254 | 's.rowid' => "company", 's.nom' => 'company', 'ps.nom' => 'company', 's.code_client' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'co.code' => 'company', 's.phone' => 'company', |
||
| 255 | 's.siren' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.siret' => 'company', 'c.rowid' => "propal", 'c.ref' => "propal", 'c.ref_client' => "propal", |
||
| 256 | 'c.fk_soc' => "propal", 'c.datec' => "propal", 'c.datep' => "propal", 'c.fin_validite' => "propal", 'c.total_ht' => "propal", |
||
| 257 | 'c.total_ttc' => "propal", 'c.fk_statut' => "propal", 'c.note_public' => "propal", 'c.note_private' => "propal", 'c.date_livraison' => "propal", |
||
| 258 | 'c.fk_user_author' => 'user', 'uc.login' => 'user', |
||
| 259 | 'c.fk_user_valid' => 'user', 'uv.login' => 'user', |
||
| 260 | 'pj.ref' => 'project', |
||
| 261 | 'cd.rowid' => 'propal_line', |
||
| 262 | 'cd.description' => "propal_line", 'cd.product_type' => 'propal_line', 'cd.tva_tx' => "propal_line", 'cd.qty' => "propal_line", |
||
| 263 | 'cd.total_ht' => "propal_line", 'cd.total_tva' => "propal_line", 'cd.total_ttc' => "propal_line", 'p.rowid' => 'product', 'p.ref' => 'product', 'p.label' => 'product' |
||
| 264 | ); |
||
| 265 | $this->export_dependencies_array[$r] = array('propal_line' => 'cd.rowid', 'product' => 'cd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
||
| 266 | $keyforselect = 'propal'; |
||
| 267 | $keyforelement = 'propal'; |
||
| 268 | $keyforaliasextra = 'extra'; |
||
| 269 | include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
||
| 270 | $keyforselect = 'propaldet'; |
||
| 271 | $keyforelement = 'propal_line'; |
||
| 272 | $keyforaliasextra = 'extra2'; |
||
| 273 | include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
||
| 274 | $keyforselect = 'product'; |
||
| 275 | $keyforelement = 'product'; |
||
| 276 | $keyforaliasextra = 'extra3'; |
||
| 277 | include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
||
| 278 | $keyforselect = 'societe'; |
||
| 279 | $keyforelement = 'company'; |
||
| 280 | $keyforaliasextra = 'extra4'; |
||
| 281 | include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
||
| 282 | |||
| 283 | $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
||
| 284 | $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s '; |
||
| 285 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_extrafields as extra4 ON s.rowid = extra4.fk_object'; |
||
| 286 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as ps ON ps.rowid = s.parent'; |
||
| 287 | if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { |
||
| 288 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
||
| 289 | } |
||
| 290 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as co ON s.fk_pays = co.rowid,'; |
||
| 291 | $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'propal as c'; |
||
| 292 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_input_reason as cir ON cir.rowid = c.fk_input_reason'; |
||
| 293 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet as pj ON c.fk_projet = pj.rowid'; |
||
| 294 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as uc ON c.fk_user_author = uc.rowid'; |
||
| 295 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as uv ON c.fk_user_valid = uv.rowid'; |
||
| 296 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'propal_extrafields as extra ON c.rowid = extra.fk_object'; |
||
| 297 | $this->export_sql_end[$r] .= ', ' . MAIN_DB_PREFIX . 'propaldet as cd'; |
||
| 298 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object'; |
||
| 299 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on (cd.fk_product = p.rowid)'; |
||
| 300 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
||
| 301 | $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal'; |
||
| 302 | $this->export_sql_end[$r] .= ' AND c.entity IN (' . getEntity('propal') . ')'; |
||
| 303 | if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { |
||
| 304 | $this->export_sql_end[$r] .= ' AND sc.fk_user = ' . (empty($user) ? 0 : $user->id); |
||
| 305 | } |
||
| 306 | |||
| 307 | // Imports |
||
| 308 | //-------- |
||
| 309 | $r = 0; |
||
| 310 | |||
| 311 | $r++; |
||
| 312 | $this->import_code[$r] = $this->rights_class . '_' . $r; |
||
| 313 | $this->import_label[$r] = 'Proposals'; // Translation key |
||
| 314 | $this->import_icon[$r] = $this->picto; |
||
| 315 | $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
||
| 316 | $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX . 'propal', 'extra' => MAIN_DB_PREFIX . 'propal_extrafields'); |
||
| 317 | $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id |
||
| 318 | $this->import_fields_array[$r] = array( |
||
| 319 | 'c.ref' => 'Ref*', |
||
| 320 | 'c.ref_client' => 'RefCustomer', |
||
| 321 | 'c.fk_soc' => 'ThirdPartyName*', |
||
| 322 | 'c.datec' => 'DateCreation', |
||
| 323 | 'c.datep' => 'DatePropal', |
||
| 324 | 'c.fin_validite' => 'DateEndPropal', |
||
| 325 | 'c.total_ht' => 'TotalHT', |
||
| 326 | 'c.total_ttc' => 'TotalTTC', |
||
| 327 | 'c.fk_statut' => 'Status*', |
||
| 328 | 'c.note_public' => 'NotePublic', |
||
| 329 | 'c.note_private' => 'NotePrivate', |
||
| 330 | 'c.date_livraison' => 'DeliveryDate', |
||
| 331 | 'c.fk_user_valid' => 'ValidatedById' |
||
| 332 | ); |
||
| 333 | if (isModEnabled("multicurrency")) { |
||
| 334 | $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency'; |
||
| 335 | $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate'; |
||
| 336 | $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; |
||
| 337 | $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; |
||
| 338 | $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; |
||
| 339 | } |
||
| 340 | // Add extra fields |
||
| 341 | $import_extrafield_sample = array(); |
||
| 342 | $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, " . $conf->entity . ")"; |
||
| 343 | $resql = $this->db->query($sql); |
||
| 344 | if ($resql) { |
||
| 345 | while ($obj = $this->db->fetch_object($resql)) { |
||
| 346 | $fieldname = 'extra.' . $obj->name; |
||
| 347 | $fieldlabel = ucfirst($obj->label); |
||
| 348 | $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ? '*' : ''); |
||
| 349 | $import_extrafield_sample[$fieldname] = $fieldlabel; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | // End add extra fields |
||
| 353 | $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'propal']; |
||
| 354 | $this->import_regex_array[$r] = ['c.ref' => '[^ ]']; |
||
| 355 | $import_sample = [ |
||
| 356 | 'c.ref' => 'PROV0077', |
||
| 357 | 'c.ref_client' => 'Client1', |
||
| 358 | 'c.fk_soc' => 'MyBigCompany', |
||
| 359 | 'c.datec' => '2020-01-01', |
||
| 360 | 'c.datep' => '2020-01-01', |
||
| 361 | 'c.fin_validite' => '2020-01-01', |
||
| 362 | 'c.total_ht' => '0', |
||
| 363 | 'c.total_ttc' => '0', |
||
| 364 | 'c.fk_statut' => '1', |
||
| 365 | 'c.note_public' => '', |
||
| 366 | 'c.note_private' => '', |
||
| 367 | 'c.date_livraison' => '2020-01-01', |
||
| 368 | 'c.fk_user_valid' => '1', |
||
| 369 | 'c.multicurrency_code' => '', |
||
| 370 | 'c.multicurrency_tx' => '1', |
||
| 371 | 'c.multicurrency_total_ht' => '0', |
||
| 372 | 'c.multicurrency_total_tva' => '0', |
||
| 373 | 'c.multicurrency_total_ttc' => '0' |
||
| 374 | ]; |
||
| 375 | $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); |
||
| 376 | $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref'); |
||
| 377 | $this->import_convertvalue_array[$r] = array( |
||
| 378 | 'c.ref' => array( |
||
| 379 | 'rule' => 'getrefifauto', |
||
| 380 | 'class' => (!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON), |
||
| 381 | 'path' => "/core/modules/propale/" . (!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON) . '.php', |
||
| 382 | 'classobject' => 'Propal', |
||
| 383 | 'pathobject' => '/comm/propal/class/propal.class.php', |
||
| 384 | ), |
||
| 385 | 'c.fk_soc' => array( |
||
| 386 | 'rule' => 'fetchidfromref', |
||
| 387 | 'file' => '/societe/class/societe.class.php', |
||
| 388 | 'class' => 'Societe', |
||
| 389 | 'method' => 'fetch', |
||
| 390 | 'element' => 'ThirdParty' |
||
| 391 | ) |
||
| 392 | ); |
||
| 393 | |||
| 394 | //Import Proposal Lines |
||
| 395 | $r++; |
||
| 396 | $this->import_code[$r] = $this->rights_class . 'line_' . $r; |
||
| 397 | $this->import_label[$r] = "ProposalLines"; // Translation key |
||
| 398 | $this->import_icon[$r] = $this->picto; |
||
| 399 | $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
||
| 400 | $this->import_tables_array[$r] = array( |
||
| 401 | 'cd' => MAIN_DB_PREFIX . 'propaldet', |
||
| 402 | 'extra' => MAIN_DB_PREFIX . 'propaldet_extrafields' |
||
| 403 | ); |
||
| 404 | $this->import_fields_array[$r] = array( |
||
| 405 | 'cd.fk_propal' => 'Proposal*', |
||
| 406 | 'cd.fk_parent_line' => 'ParentLine', |
||
| 407 | 'cd.fk_product' => 'IdProduct', |
||
| 408 | 'cd.description' => 'LineDescription', |
||
| 409 | 'cd.product_type' => 'TypeOfLineServiceOrProduct', |
||
| 410 | 'cd.tva_tx' => 'LineVATRate', |
||
| 411 | 'cd.qty' => 'LineQty', |
||
| 412 | 'cd.remise_percent' => 'Reduc. Percent', |
||
| 413 | 'cd.price' => 'Price', |
||
| 414 | 'cd.subprice' => 'Sub Price', |
||
| 415 | 'cd.total_ht' => 'LineTotalHT', |
||
| 416 | 'cd.total_tva' => 'LineTotalVAT', |
||
| 417 | 'cd.total_ttc' => 'LineTotalTTC', |
||
| 418 | 'cd.date_start' => 'Start Date', |
||
| 419 | 'cd.date_end' => 'End Date', |
||
| 420 | 'cd.buy_price_ht' => 'LineBuyPriceHT' |
||
| 421 | ); |
||
| 422 | if (isModEnabled("multicurrency")) { |
||
| 423 | $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency'; |
||
| 424 | $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate'; |
||
| 425 | $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT'; |
||
| 426 | $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT'; |
||
| 427 | $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC'; |
||
| 428 | } |
||
| 429 | // Add extra fields |
||
| 430 | $import_extrafield_sample = array(); |
||
| 431 | $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, " . $conf->entity . ")"; |
||
| 432 | $resql = $this->db->query($sql); |
||
| 433 | if ($resql) { |
||
| 434 | while ($obj = $this->db->fetch_object($resql)) { |
||
| 435 | $fieldname = 'extra.' . $obj->name; |
||
| 436 | $fieldlabel = ucfirst($obj->label); |
||
| 437 | $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ? '*' : ''); |
||
| 438 | $import_extrafield_sample[$fieldname] = $fieldlabel; |
||
| 439 | } |
||
| 440 | } |
||
| 441 | // End add extra fields |
||
| 442 | $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'propaldet'); |
||
| 443 | $this->import_regex_array[$r] = array('cd.product_type' => '[0|1]$'); |
||
| 444 | $import_sample = array( |
||
| 445 | 'cd.fk_propal' => 'PROV(0001)', |
||
| 446 | 'cd.fk_parent_line' => '', |
||
| 447 | 'cd.fk_product' => '', |
||
| 448 | 'cd.description' => 'Line description', |
||
| 449 | 'cd.product_type' => '1', |
||
| 450 | 'cd.tva_tx' => '0', |
||
| 451 | 'cd.qty' => '2', |
||
| 452 | 'cd.remise_percent' => '0', |
||
| 453 | 'cd.price' => '', |
||
| 454 | 'cd.subprice' => '5000', |
||
| 455 | 'cd.total_ht' => '10000', |
||
| 456 | 'cd.total_tva' => '0', |
||
| 457 | 'cd.total_ttc' => '10100', |
||
| 458 | 'cd.date_start' => '', |
||
| 459 | 'cd.date_end' => '', |
||
| 460 | 'cd.buy_price_ht' => '7000', |
||
| 461 | 'cd.multicurrency_code' => 'JPY', |
||
| 462 | 'cd.multicurrency_tx' => '1', |
||
| 463 | 'cd.multicurrency_total_ht' => '10000', |
||
| 464 | 'cd.multicurrency_total_tva' => '0', |
||
| 465 | 'cd.multicurrency_total_ttc' => '10100' |
||
| 466 | ); |
||
| 467 | $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); |
||
| 468 | $this->import_updatekeys_array[$r] = array('cd.fk_propal' => 'Quotation Id', 'cd.fk_product' => 'Product Id'); |
||
| 469 | $this->import_convertvalue_array[$r] = array( |
||
| 470 | 'cd.fk_propal' => array( |
||
| 471 | 'rule' => 'fetchidfromref', |
||
| 472 | 'file' => '/comm/propal/class/propal.class.php', |
||
| 473 | 'class' => 'Propal', |
||
| 474 | 'method' => 'fetch' |
||
| 475 | ) |
||
| 519 |