Skip to content

Commit

Permalink
[RegistrationCertificate] add: create default lot if no lot is select…
Browse files Browse the repository at this point in the history
…ed for creation
  • Loading branch information
Théo David committed May 27, 2022
1 parent b7d2ab5 commit 4d5a263
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
20 changes: 15 additions & 5 deletions class/registrationcertificatefr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once __DIR__.'/../lib/dolicar_functions.lib.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';

Expand Down Expand Up @@ -101,7 +103,7 @@ class RegistrationCertificateFr extends CommonObject
public $fields=array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'index'=>1, 'searchall'=>1, 'validate'=>'1', 'comment'=>"Reference of object"),
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>560, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'css'=>'maxwidth500 widthcentpercentminusxx', 'help'=>"LinkToThirparty", 'validate'=>'1',),
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>14, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'css'=>'maxwidth500 widthcentpercentminusxx', 'help'=>"LinkToThirparty", 'validate'=>'1',),
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>40, 'notnull'=>1, 'visible'=>-2,),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>-2,),
'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>540, 'notnull'=>1, 'visible'=>-2,),
Expand All @@ -110,7 +112,7 @@ class RegistrationCertificateFr extends CommonObject
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>60, 'notnull'=>-1, 'visible'=>-2,),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>70, 'notnull'=>1, 'visible'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Validé', '9'=>'Annulé')),
'ref_ext' => array('type'=>'varchar(128)', 'label'=>'RefExt', 'enabled'=>'1', 'position'=>20, 'notnull'=>0, 'visible'=>0,),
'a_registration_number' => array('type'=>'varchar(128)', 'label'=>'RegistrationNumber', 'enabled'=>'1', 'position'=>80, 'notnull'=>1, 'visible'=>1,),
'a_registration_number' => array('type'=>'varchar(128)', 'label'=>'RegistrationNumber', 'enabled'=>'1', 'position'=>11, 'notnull'=>1, 'visible'=>1,),
'b_first_registration_date' => array('type'=>'datetime', 'label'=>'FirstRegistrationDate', 'enabled'=>'1', 'position'=>90, 'notnull'=>0, 'visible'=>3,),
'c1_owner_fullname' => array('type'=>'varchar(255)', 'label'=>'OwnerFullName', 'enabled'=>'1', 'position'=>100, 'notnull'=>0, 'visible'=>3,),
'c3_registration_address' => array('type'=>'text', 'label'=>'RegistrationAddress', 'enabled'=>'1', 'position'=>110, 'notnull'=>0, 'visible'=>3,),
Expand All @@ -122,7 +124,7 @@ class RegistrationCertificateFr extends CommonObject
'c4a_owner_vehicle' => array('type'=>'boolean', 'label'=>'OwnerVehicle', 'enabled'=>'1', 'position'=>120, 'notnull'=>0, 'visible'=>3,),
'd2_vehicle_type' => array('type'=>'varchar(128)', 'label'=>'VehicleType', 'enabled'=>'1', 'position'=>160, 'notnull'=>0, 'visible'=>3,),
'd21_vehicle_cnit' => array('type'=>'varchar(128)', 'label'=>'VehicleCNIT', 'enabled'=>'1', 'position'=>170, 'notnull'=>0, 'visible'=>3,),
'd3_vehicle_model' => array('type'=>'integer:Product:product/class/product.class.php:1', 'label'=>'VehicleModel', 'enabled'=>'1', 'position'=>180, 'notnull'=>1, 'visible'=>3, 'css'=>'maxwidth500',),
'd3_vehicle_model' => array('type'=>'integer:Product:product/class/product.class.php:1', 'label'=>'VehicleModel', 'enabled'=>'1', 'position'=>13, 'notnull'=>1, 'visible'=>3, 'css'=>'maxwidth500',),
'd1_vehicle_brand' => array('type'=>'varchar(128)', 'label'=>'VehicleBrand', 'enabled'=>'1', 'position'=>150, 'notnull'=>0, 'visible'=>3,),
'f3_ptra' => array('type'=>'integer', 'label'=>'PTRA', 'enabled'=>'1', 'position'=>220, 'notnull'=>0, 'visible'=>3,),
'g_vehicle_weight' => array('type'=>'integer', 'label'=>'VehicleWeight', 'enabled'=>'1', 'position'=>230, 'notnull'=>0, 'visible'=>3,),
Expand Down Expand Up @@ -156,8 +158,8 @@ class RegistrationCertificateFr extends CommonObject
'z2_specific_details' => array('type'=>'text', 'label'=>'SpecificDetails2', 'enabled'=>'1', 'position'=>510, 'notnull'=>0, 'visible'=>3,),
'z3_specific_details' => array('type'=>'text', 'label'=>'SpecificDetails3', 'enabled'=>'1', 'position'=>520, 'notnull'=>0, 'visible'=>3,),
'z4_specific_details' => array('type'=>'text', 'label'=>'SpecificDetails4', 'enabled'=>'1', 'position'=>530, 'notnull'=>0, 'visible'=>3,),
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'1', 'position'=>570, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500', 'validate'=>'1',),
'fk_lot' => array('type'=>'integer:Productlot:product/stock/class/productlot.class.php:1', 'label'=>'Batch', 'enabled'=>'1', 'position'=>580, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500', 'validate'=>'1',),
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'1', 'position'=>16, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500', 'validate'=>'1',),
'fk_lot' => array('type'=>'integer:Productlot:product/stock/class/productlot.class.php:1', 'label'=>'Batch', 'enabled'=>'1', 'position'=>15, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500', 'validate'=>'1',),
);
public $rowid;
public $ref;
Expand Down Expand Up @@ -311,6 +313,13 @@ public function create(User $user, $notrigger = false)
{
$this->ref = $this->a_registration_number;
$this->status = 1;
if (empty($this->fk_lot)) {
$lot_id = createDefaultLot($this->d3_vehicle_model);
$this->fk_lot = $lot_id;
}
$product = new Product($this->db);
$product->fetch($this->d3_vehicle_model);

$resultcreate = $this->createCommon($user, $notrigger);

return $resultcreate;
Expand Down Expand Up @@ -534,6 +543,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
*/
public function update(User $user, $notrigger = false)
{
$this->ref = $this->a_registration_number;
return $this->updateCommon($user, $notrigger);
}

Expand Down
2 changes: 1 addition & 1 deletion langs/fr_FR/dolicar.lang
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ Car = Voiture
Truck = Poids lourd
Bicycle = Vélo
CommercialVehicle = Utilitaire

Batch = Numéro de châssis
56 changes: 56 additions & 0 deletions lib/dolicar_functions.lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/* Copyright (C) 2022 SuperAdmin <test@test.fr>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file dolicar/lib/dolicar_functions.lib.php
* \ingroup dolicar
* \brief Library files with common functions for DoliCar
*/

/**
* Prepare admin pages header
*
* @return float|int
*/
function createDefaultLot($product_id)
{
global $db, $user;

require_once __DIR__ . '/../../../product/stock/class/productlot.class.php';

$productlot = new Productlot($db);
$productlot->fk_product = $product_id;
$productlot->batch = generate_random_id();
return $productlot->create($user);
}

/**
* Generate a random id
*
* @param int $car Length of string to generate key
* @return string
*/
function generate_random_id($car = 16)
{
$string = "";
$chaine = "abcdefghijklmnopqrstuvwxyz123456789";
mt_srand((double) microtime() * 1000000);
for ($i = 0; $i < $car; $i++) {
$string .= $chaine[mt_rand() % strlen($chaine)];
}
return $string;
}
2 changes: 1 addition & 1 deletion sql/llx_dolicar_registrationcertificatefr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CREATE TABLE llx_dolicar_registrationcertificatefr(
c4a_owner_vehicle boolean,
d2_vehicle_type varchar(128),
d21_vehicle_cnit varchar(128),
d3_vehicle_model integer NOT NULL,
d3_vehicle_model integer NOT NULL,
d1_vehicle_brand varchar(128),
f3_ptra integer,
g_vehicle_weight integer,
Expand Down

0 comments on commit 4d5a263

Please sign in to comment.