Add generated id to customer creation. #638
This commit is contained in:
parent
c40143dced
commit
46be0d6df0
3 changed files with 46 additions and 4 deletions
|
|
@ -19,6 +19,8 @@ use App\Entity\Vehicle;
|
|||
use App\Ramcar\FuelType;
|
||||
use App\Ramcar\VehicleStatusCondition;
|
||||
|
||||
use App\Service\CustomerGeneratedIdService;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class CreateCustomerFromWarrantyCommand extends Command
|
||||
|
|
@ -33,9 +35,12 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
protected $cvu_mfg_id;
|
||||
protected $cvu_brand_id;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, $cvu_mfg_id, $cvu_brand_id)
|
||||
protected $cust_gen_id;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, $cvu_mfg_id, $cvu_brand_id, CustomerGeneratedIdService $cust_gen_id)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->cust_gen_id = $cust_gen_id;
|
||||
|
||||
$this->cvu_mfg_id = $cvu_mfg_id;
|
||||
$this->cvu_brand_id = $cvu_brand_id;
|
||||
|
|
@ -154,6 +159,7 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
error_log("($total_warr) processing $w_mobile_num from warranty...");
|
||||
|
||||
$customers = $this->findCustomerByNumber($w_mobile_num);
|
||||
$new_cust = null;
|
||||
|
||||
if (!empty($customers))
|
||||
{
|
||||
|
|
@ -232,6 +238,16 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
$total_cv_added++;
|
||||
}
|
||||
}
|
||||
if ($new_cust != null)
|
||||
{
|
||||
// TODO: temporary fix on how to save customer with a generated id
|
||||
// since we need to keep generating an id until we are sure that there
|
||||
// are no duplicates for generated id
|
||||
// when saving the customer. This is an additional check.
|
||||
// This will keep generating an id until a unique id is generated
|
||||
// and the customer entity can then be inserted
|
||||
$cust_gen_id->saveCustomerWithGeneratedId($new_cust);
|
||||
}
|
||||
$this->em->flush();
|
||||
$this->em->clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ use Exception;
|
|||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerTag;
|
||||
|
||||
use App\Service\CustomerGeneratedIdService;
|
||||
|
||||
class ImportCarClubCustomerDataCommand extends Command
|
||||
{
|
||||
// field index in csv file
|
||||
|
|
@ -26,10 +28,12 @@ class ImportCarClubCustomerDataCommand extends Command
|
|||
|
||||
protected $em;
|
||||
protected $cust_tag_hash;
|
||||
protected $cust_gen_id;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, CustomerGeneratedIdService $cust_gen_id)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->cust_gen_id = $cust_gen_id;
|
||||
$this->loadCustomerTags();
|
||||
|
||||
parent::__construct();
|
||||
|
|
@ -173,6 +177,15 @@ class ImportCarClubCustomerDataCommand extends Command
|
|||
->addCustomerTag($promo_tag);
|
||||
|
||||
$this->em->persist($new_cust);
|
||||
|
||||
// TODO: temporary fix on how to save customer with a generated id
|
||||
// since we need to keep generating an id until we are sure that there
|
||||
// are no duplicates for generated id
|
||||
// when saving the customer. This is an additional check.
|
||||
// This will keep generating an id until a unique id is generated
|
||||
// and the customer entity can then be inserted
|
||||
$this->cust_gen_id->saveCustomerWithGeneratedId($new_cust);
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $new_cust;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ use App\Entity\CustomerTag;
|
|||
use App\Entity\CarClubCustomerHub;
|
||||
use App\Entity\Hub;
|
||||
|
||||
use App\Service\CustomerGeneratedIdService;
|
||||
|
||||
class ImportCarClubCustomerHubCommand extends Command
|
||||
{
|
||||
// field index in csv file
|
||||
|
|
@ -28,10 +30,12 @@ class ImportCarClubCustomerHubCommand extends Command
|
|||
|
||||
protected $em;
|
||||
protected $cust_tag_hash;
|
||||
protected $cust_gen_id;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, CustomerGeneratedIdService $cust_gen_id)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->cust_gen_id = $cust_gen_id;
|
||||
$this->loadCustomerTags();
|
||||
|
||||
parent::__construct();
|
||||
|
|
@ -188,7 +192,16 @@ class ImportCarClubCustomerHubCommand extends Command
|
|||
->addCustomerTag($promo_tag);
|
||||
|
||||
$this->em->persist($new_cust);
|
||||
$this->em->flush();
|
||||
|
||||
// TODO: temporary fix on how to save customer with a generated id
|
||||
// since we need to keep generating an id until we are sure that there
|
||||
// are no duplicates for generated id
|
||||
// when saving the customer. This is an additional check.
|
||||
// This will keep generating an id until a unique id is generated
|
||||
// and the customer entity can then be inserted
|
||||
$this->cust_gen_id->saveCustomerWithGeneratedId($new_cust);
|
||||
|
||||
//$this->em->flush();
|
||||
|
||||
return $new_cust;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue