Apply branch 551 changes. #567

This commit is contained in:
Korina Cordero 2021-05-19 08:10:18 +00:00
parent d2af08a5eb
commit 66e1a71890
20 changed files with 806 additions and 105 deletions

View file

@ -266,3 +266,7 @@ services:
event: 'postPersist'
entity: 'App\Entity\CustomerVehicle'
# warranty api logger
App\Service\WarrantyAPILogger:
arguments:
$em: "@doctrine.orm.entity_manager"

View file

@ -16,20 +16,25 @@ use App\Entity\JobOrder;
use App\Entity\Warranty;
use App\Entity\SAPBattery;
use App\Service\WarrantyAPILogger;
use App\Ramcar\ServiceType;
use App\Ramcar\WarrantyStatus;
use App\Ramcar\WarrantySource;
use DoctrineExtensions\Query\Mysql\DateFormat;
class GenerateWarrantyFromJobOrderCommand extends Command
{
protected $em;
protected $logger;
protected $sapbatt_hash;
protected $warranties_hash;
public function __construct(EntityManagerInterface $em)
public function __construct(EntityManagerInterface $em, WarrantyAPILogger $logger)
{
$this->em = $em;
$this->logger = $logger;
$this->loadSAPBatteries();
@ -210,6 +215,26 @@ class GenerateWarrantyFromJobOrderCommand extends Command
$sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy) VALUES ' . $values . "\n";
echo $sql_statement;
$db = $this->em->getConnection();
$stmt = $db->prepare($sql_statement);
$stmt->execute();
// log warranty creation
$log_data = [
'battery_model_id' => $bty_model_id,
'battery_size_id' => $bty_size_id,
'warranty_class' => $warranty_class,
'plate_number' => $cleaned_plate_number,
'date_create' => $date_create,
'date_purchase' => $date_purchase,
'date_expire' => $date_expire,
'sap_code' => $sap_code,
'first_name' => $first_name,
'last_name' => $last_name,
'mobile_number' => $mobile_number,
];
$this->logger->logWarrantyInfo($log_data, '', 'internal', 'create', WarrantySource::COMMAND);
}
else

View file

@ -28,6 +28,7 @@ use App\Ramcar\TradeInType;
use App\Ramcar\JOEventType;
use App\Ramcar\AdvanceOrderSlot;
use App\Ramcar\AutoAssignStatus;
use App\Ramcar\WarrantySource;
use App\Service\InvoiceGeneratorInterface;
use App\Service\RisingTideGateway;
@ -37,6 +38,7 @@ use App\Service\RiderTracker;
use App\Service\MapTools;
use App\Service\InventoryManager;
use App\Service\RiderAssignmentHandlerInterface;
use App\Service\WarrantyAPILogger;
use App\Entity\MobileSession;
use App\Entity\Customer;
@ -2856,8 +2858,8 @@ class APIController extends Controller implements LoggedController
'date_purchase' => $date_purchase_cust,
'invoice' => $invoice_url,
'warr_card' => $warr_card_url,
'dealer_name' => $warr->getDealerName() ?? '',
'dealer_address' => $warr->getDealerAddress() ?? '',
'dealer_name' => $warr->getDealerName() ?? '',
'dealer_address' => $warr->getDealerAddress() ?? '',
];
}
else
@ -2877,8 +2879,8 @@ class APIController extends Controller implements LoggedController
'date_purchase' => $today->format('Y-m-d'),
'invoice' => '',
'warr_card' => '',
'dealer_name' => '',
'dealer_address' => '',
'dealer_name' => '',
'dealer_address' => '',
];
}
}
@ -2905,7 +2907,16 @@ class APIController extends Controller implements LoggedController
}
$sku = $warr_serial->getSKU();
$batt = $em->getRepository(SAPBattery::class)->find($sku);
$batt = null;
$cat_name = '';
if ($sku != null)
$batt = $em->getRepository(SAPBattery::class)->find($sku);
else
{
// get the category name of the serial
$cat_name = $warr_serial->getMetaInfo('category_name');
}
// TODO: put this in a config file
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
if ($batt != null)
@ -2919,7 +2930,7 @@ class APIController extends Controller implements LoggedController
else
{
$battery = [
'brand' => '',
'brand' => $cat_name,
'size' => '',
'image_url' => '',
];
@ -2979,7 +2990,8 @@ class APIController extends Controller implements LoggedController
return $serial . '/' . $filename;
}
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt, TranslatorInterface $trans)
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt,
TranslatorInterface $trans, WarrantyAPILogger $logger)
{
// check required parameters and api key
$required_params = [
@ -3001,22 +3013,37 @@ class APIController extends Controller implements LoggedController
$inv_filename = $this->handlePictureUpload($invoice, $upload_dir, $serial, 'invoice');
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
$user_id = $req->query->get('api_key');
$log_data = [
'plate_number' => $req->request->get('plate_num'),
'first_name' => $req->request->get('first_name'),
'last_name' => $req->request->get('last_name'),
'date_purchase' => $req->request->get('date_purchase'),
];
$action = 'create';
$source = WarrantySource::MOBILE;
$res = $this->checkParamsAndKey($req, $em, $required_params);
if ($res->isError())
{
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
return $res->getReturnResponse();
}
// update customer information
// $cust = $this->updateCustomerInfo($req, $em);
// update warranty
$res = $this->updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename);
$res = $this->updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename,
$logger, $log_data, $user_id, $action, $source);
$em->flush();
return $res->getReturnResponse();
}
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
$logger, $log_data, $user_id, $action, $source)
{
// get serial
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
@ -3024,6 +3051,7 @@ class APIController extends Controller implements LoggedController
{
$res->setError(true)
->setErrorMessage('Invalid warranty serial code.');
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
return $res;
}
@ -3049,6 +3077,7 @@ class APIController extends Controller implements LoggedController
{
$res->setError(true)
->setErrorMessage('Warranty registred to a vehicle not in your list of vehicles.');
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
return $res;
}
@ -3062,12 +3091,17 @@ class APIController extends Controller implements LoggedController
// get sap battery
$sku = $warr_serial->getSKU();
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
if ($sap_bty == null)
$sap_bty = null;
if ($sku != null)
{
$res->setError(true)
->setErrorMessage('Could not find battery entry for warranty.');
return $res;
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
if ($sap_bty == null)
{
$res->setError(true)
->setErrorMessage('Could not find battery entry for warranty.');
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
return $res;
}
}
// default date purchase to today
@ -3080,6 +3114,7 @@ class APIController extends Controller implements LoggedController
{
$res->setError(true)
->setErrorMessage('Invalid date format for date of purchase.');
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
return $res;
}
@ -3124,6 +3159,8 @@ class APIController extends Controller implements LoggedController
// set data to retrun to user
$res->setData($data);
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
// send sms
error_log('sending sms to - ' . $this->session->getPhoneNumber());
$rt->sendSMS($this->session->getPhoneNumber(), 'MOTOLITE', $sms_msg);

View file

@ -14,6 +14,7 @@ use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Service\RisingTideGateway;
use App\Service\WarrantyAPILogger;
use App\Entity\WarrantySerial;
use App\Entity\Warranty;
@ -32,6 +33,7 @@ use App\Ramcar\WarrantyClass;
use App\Ramcar\WarrantyStatus;
use App\Ramcar\FuelType;
use App\Ramcar\VehicleStatusCondition;
use App\Ramcar\WarrantySource;
use DateTime;
@ -73,13 +75,14 @@ class CustomerWarrantyController extends APIController
return $missing;
}
protected function checkRequiredParams(Request $req, $params)
protected function checkRequiredParams(Request $req, $params, $logger, $log_data, $user_id, $action, $source)
{
// check required parameters
$missing = $this->checkMissingParameters($req, $params);
if (count($missing) > 0)
{
$miss_string = implode(', ', $missing);
$logger->logWarrantyInfo($log_data, 'Missing parameter(s): ' . $miss_string, $user_id, $action, $source);
return new APIResponse(false, 'Missing parameter(s): ' . $miss_string);
}
@ -96,16 +99,24 @@ class CustomerWarrantyController extends APIController
return preg_replace('/\s+/', '', strtoupper($plate_num));
}
public function check($serial, EntityManagerInterface $em, Request $req)
public function check($serial, EntityManagerInterface $em, Request $req, WarrantyAPILogger $logger)
{
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
$log_data = [
'serial' => $serial,
];
$action = 'check';
$source = WarrantySource::CAPI;
// check required parameters
$required_params = [];
$res = $this->checkRequiredParams($req, $required_params);
if (!$res)
return $res;
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action, $source);
if (!$res)
return $res;
error_log('check warranty serial');
// TODO: add logging for the other scenarios
// check if warranty serial is there
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]);
@ -232,7 +243,17 @@ class CustomerWarrantyController extends APIController
}
$sku = $warr_serial->getSKU();
$batt = $em->getRepository(SAPBattery::class)->find($sku);
// check if sku is null
$batt = null;
$cat_name = '';
if ($sku != null)
$batt = $em->getRepository(SAPBattery::class)->find($sku);
else
{
// get the category name of the serial
$cat_name = $warr_serial->getMetaInfo('category_name');
}
// TODO: put this in a config file
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
if ($batt != null)
@ -246,7 +267,7 @@ class CustomerWarrantyController extends APIController
else
{
$battery = [
'brand' => '',
'brand' => $cat_name,
'size' => '',
'image_url' => '',
];
@ -275,18 +296,42 @@ class CustomerWarrantyController extends APIController
}
public function register($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt, TranslatorInterface $trans)
public function register($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt, TranslatorInterface $trans,
WarrantyAPILogger $logger)
{
error_log('HERE - register');
// set up information for logging
// get user from header
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
$log_data = [
'serial' => $serial,
'plate_number' => $req->request->get('plate_num'),
'first_name' => $req->request->get('first_name'),
'last_name' => $req->request->get('last_name'),
'vmake_id' => $req->request->get('vmake_id'),
'contact_number' => $req->request->get('contact_num'),
'email' => $req->request->get('email'),
'invoice' => $req->request->get('invoice'),
];
$action = 'create/update';
$source = WarrantySource::CAPI;
error_log('SOURCE: ' . $source);
// TODO: maybe add vmake_id? since warranty cannot be created with no vmake
// TODO: maybe also add mobile and email since customer creation won't let mobile and email be null
// check required parameters
$required_params = [
'first_name',
'last_name',
'plate_num'
];
$res = $this->checkRequiredParams($req, $required_params);
if (!$res)
return $res;
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action, $source);
if (!$res)
return $res;
// file uploads
$invoice = $req->files->get('invoice');
@ -299,12 +344,13 @@ class CustomerWarrantyController extends APIController
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
// do actual registering
$res = $this->updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename);
$res = $this->updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename,
$logger, $log_data, $user_id, $action, $source);
// flush to db
$em->flush();
return $res;
return $res;
return new APIResponse(true, 'Warranty registered.');
}
@ -340,7 +386,8 @@ class CustomerWarrantyController extends APIController
return $serial . '/' . $filename;
}
protected function updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
protected function updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
$logger, $log_data, $user_id, $action, $source)
{
$plate_num = $this->cleanPlateNumber($req->request->get('plate_num'));
@ -349,6 +396,7 @@ class CustomerWarrantyController extends APIController
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
if ($warr_serial == null)
{
$logger->logWarrantyInfo($log_data, 'Invalid warranty serial code..', $user_id, $action, $source);
return new APIResponse(false, 'Invalid warranty serial code.');
}
@ -364,6 +412,7 @@ class CustomerWarrantyController extends APIController
if ($plate_num != $warr_plate_num)
{
$logger->logWarrantyInfo($log_data, 'Plate number does not match vehicle registered to warranty.', $user_id, $action, $source);
return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.');
}
@ -381,10 +430,17 @@ class CustomerWarrantyController extends APIController
error_log('sap battery check');
// get sap battery
$sku = $warr_serial->getSKU();
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
if ($sap_bty == null)
$sap_bty = null;
// check if sku is null
if ($sku != null)
{
return new APIResponse(false, 'Could not find battery entry for warranty.');
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
if ($sap_bty == null)
{
$logger->logWarrantyInfo($log_data, 'Cound not find battery entry for warranty.', $user_id, $action, $source);
return new APIResponse(false, 'Could not find battery entry for warranty.');
}
}
// vehicle fetch
@ -395,6 +451,7 @@ class CustomerWarrantyController extends APIController
$vehicle = $em->getRepository(Vehicle::class)->find($vmake_id);
if ($vehicle == null)
{
$logger->logWarrantyInfo($log_data, 'Could not find vehicle specified for warranty.', $user_id, $action, $source);
return new APIResponse(false, 'Could not find vehicle specified for warranty.');
}
}
@ -405,13 +462,17 @@ class CustomerWarrantyController extends APIController
$date_pur = new DateTime();
// get date purchase specified by customer
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
if (!$date_pur_cust)
if (!empty($req->request->get('date_purchase')))
{
return new APIResponse(false, 'Invalid date format for date of purchase.');
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
if (!$date_pur_cust)
{
$logger->logWarrantyInfo($log_data, 'Invalid date format for date of purchase.', $user_id, $action, $source);
return new APIResponse(false, 'Invalid date format for date of purchase.');
}
}
// chstomer check
// customer check
$priv_promo = $req->request->get('priv_promo', false);
if ($cust == null)
{
@ -483,14 +544,16 @@ class CustomerWarrantyController extends APIController
$em->persist($warr);
// TODO: check if we need to do anyting else
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
// TODO: check if we need to do anything else
$data = [];
// send sms confirmation
$this->sendSMSConfirmation($rt, $req->request->get('contact_num'), $sms_message);
return new APIResponse(true, 'Warranty registered.', $data);
return new APIResponse(true, 'Warranty registered.', $data);
}
protected function sendSMSConfirmation($rt, $num, $message)

View file

@ -20,12 +20,16 @@ use App\Entity\PrivacyPolicy;
use App\Entity\Customer;
use App\Entity\CustomerVehicle;
use App\Entity\Vehicle;
use App\Entity\WarrantyAPILog;
use App\Service\WarrantyAPILogger;
use App\Ramcar\NameValue;
use App\Ramcar\WarrantyClass;
use App\Ramcar\WarrantyStatus;
use App\Ramcar\FuelType;
use App\Ramcar\VehicleStatusCondition;
use App\Ramcar\WarrantySource;
use DateTime;
@ -142,7 +146,7 @@ class WarrantyController extends APIController
return new APIResponse(true, 'Warranties found.', $data);
}
public function register(Request $req, EntityManagerInterface $em)
public function register(Request $req, EntityManagerInterface $em, WarrantyAPILogger $logger)
{
$this->denyAccessUnlessGranted('warranty.register.battery', null, 'No access.');
@ -159,10 +163,31 @@ class WarrantyController extends APIController
'battery_size_id',
*/
];
// set up information for logging
// get user from header
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
$log_data = [
'serial' => $serial,
'date_expire' => $date_expire_string,
'date_pur_string' => $date_pur_string,
'warranty_class' => $warr_class,
'plate_number' => $plate,
'sku' => $sku,
'first_name' => $fname,
'last_name' => $lname,
'mobile_number' => $mnum,
];
$action = 'create';
$source = WarrantySource::CAPI;
$msg = $this->checkRequiredParameters($req, $params);
error_log('msg - ' . $msg);
if ($msg)
{
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action, $source);
return new APIResponse(false, $msg);
}
$serial = $req->request->get('serial');
$date_expire_string = $req->request->get('date_expire');
@ -183,26 +208,48 @@ class WarrantyController extends APIController
// wrong date expire format
$date_expire = DateTime::createFromFormat('Ymd', $date_expire_string);
if ($date_expire === false)
{
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_expire.', $user_id, $action, $source);
return new APIResponse(false, 'Wrong date format: date_expire.');
}
// wrong date purchase format
$date_pur = DateTime::createFromFormat('Ymd', $date_pur_string);
if ($date_pur === false)
{
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_purchase', $user_id, $action, $source);
return new APIResponse(false, 'Wrong date format: date_purchase.');
}
// valid warranty class
if (!WarrantyClass::validate($warr_class))
{
$logger->logWarrantyInfo($log_data, 'Invalid warranty class.', $user_id, $action, $source);
return new APIResponse(false, 'Invalid warranty class.');
}
// plate number
$plate = Warranty::cleanPlateNumber($plate);
if (!$plate)
{
$logger->logWarrantyInfo($log_data, 'Invalid plate number.', $user_id, $action, $source);
return new APIResponse(false, 'Invalid plate number.');
}
// battery
$batt = $em->getRepository(SAPBattery::class)->find($sku);
if ($batt == null)
return new APIResponse(false, 'Invalid battery SKU.');
// check if sku is blank
if ((empty($sku)) || ($sku == null))
$batt = null;
else
{
// battery
$batt = $em->getRepository(SAPBattery::class)->find($sku);
if ($batt == null)
{
$logger->logWarrantyInfo($log_data, 'Invalid battery SKU.', $user_id, $action, $source);
return new APIResponse(false, 'Invalid battery SKU.');
}
}
/*
// battery model
@ -239,6 +286,7 @@ class WarrantyController extends APIController
}
catch (UniqueConstraintViolationException $e)
{
$logger->logWarrantyInfo($log_data, 'Duplicate serial encountered.', $user_id, $action, $source);
return new APIResponse(false, 'Duplicate serial encountered.');
}
@ -247,10 +295,13 @@ class WarrantyController extends APIController
'warranty' => $this->generateWarrantyData($warr),
];
// log creation of warranty data
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
return new APIResponse(true, 'Warranty registered.', $data);
}
public function claim(Request $req, EntityManagerInterface $em, $id)
public function claim(Request $req, EntityManagerInterface $em, $id, WarrantyAPILogger $logger)
{
$this->denyAccessUnlessGranted('warranty.claim', null, 'No access.');
@ -258,26 +309,49 @@ class WarrantyController extends APIController
$params = [
'serial',
];
$serial = $req->request->get('serial');
// set up information for logging
// get user from header
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
$log_data = [
'serial' => $serial,
'id' => $id,
];
$action = 'claim';
$source = WarrantySource::CAPI;
$msg = $this->checkRequiredParameters($req, $params);
if ($msg)
{
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action, $source);
return new APIResponse(false, $msg);
}
// no warranty
$warr = $em->getRepository(Warranty::class)->find($id);
if ($warr == null)
{
$logger->logWarrantyInfo($log_data, 'No warranty found with that id.', $user_id, $action, $source);
return new APIResponse(false, 'No warranty found with that id.', null, 404);
}
// warranty is not active
if (!$warr->canClaim())
{
$logger->logWarrantyInfo($log_data, 'Warranty is not active.', $user_id, $action, $source);
return new APIResponse(false, 'Warranty is not active.');
}
// check if new serial has been used
$serial = $req->request->get('serial');
$clean_serial = $this->cleanSerial($serial);
$check_warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
if ($check_warr != null)
{
$logger->logWarrantyInfo($log_data, 'Serial for replacement has already been used.', $user_id, $action, $source);
return new APIResponse(false, 'Serial for replacement has already been used.');
}
// set status to claim
$warr->setStatus(WarrantyStatus::CLAIMED)
@ -299,10 +373,10 @@ class WarrantyController extends APIController
$em->persist($new_warr);
$em->flush();
// TODO: claim log
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
return new APIResponse(true, 'Warranty claimed successfully.');
}
@ -383,9 +457,16 @@ class WarrantyController extends APIController
return new APIResponse(false, 'Invalid plate number.');
// battery
$batt = $em->getRepository(SAPBattery::class)->find($sku);
if ($batt == null)
return new APIResponse(false, 'Invalid battery SKU.');
// check if sku is blank
if ((empty($sku)) || ($sku == null))
$batt = null;
else
{
// battery
$batt = $em->getRepository(SAPBattery::class)->find($sku);
if ($batt == null)
return new APIResponse(false, 'Invalid battery SKU.');
}
$warr->setSerial($serial)
->setWarrantyClass($warr_class)
@ -634,6 +715,7 @@ class WarrantyController extends APIController
$w_last_name = $warranty->getLastName();
$new_cust = new Customer();
// TODO: add customer source
$new_cust->setFirstName($w_first_name)
->setLastName($w_last_name)
->setPhoneMobile($w_mobile_num);

View file

@ -12,8 +12,10 @@ use App\Entity\CustomerVehicle;
use App\Ramcar\WarrantyClass;
use App\Ramcar\WarrantyStatus;
use App\Ramcar\WarrantySource;
use App\Service\WarrantyHandler;
use App\Service\WarrantyAPILogger;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
@ -149,7 +151,7 @@ class WarrantyController extends Controller
return $this->render('warranty/form.html.twig', $params);
}
public function addSubmit(Request $req, ValidatorInterface $validator)
public function addSubmit(Request $req, ValidatorInterface $validator, WarrantyAPILogger $logger)
{
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
@ -181,31 +183,49 @@ class WarrantyController extends Controller
}
// custom validation for battery model
$model = $em->getRepository(BatteryModel::class)
->find($req->request->get('battery_model'));
if (empty($model))
$error_array['battery_model'] = 'Invalid model selected.';
// check if battery model is blank
$bmodel = $req->request->get('battery_model');
if (!empty($bmodel))
{
$model = $em->getRepository(BatteryModel::class)
->find($req->request->get('battery_model'));
if (empty($model))
$error_array['battery_model'] = 'Invalid model selected.';
else
$obj->setBatteryModel($model);
}
else
$obj->setBatteryModel($model);
$obj->setBatteryModel(NULL);
// custom validation for battery size
$size = $em->getRepository(BatterySize::class)
->find($req->request->get('battery_size'));
if (empty($size))
$error_array['battery_size'] = 'Invalid size selected.';
// check if battery size is blank
$bsize = $req->request->get('battery_size');
if (!empty($bsize))
{
$size = $em->getRepository(BatterySize::class)
->find($req->request->get('battery_size'));
if (empty($size))
$error_array['battery_size'] = 'Invalid size selected.';
else
$obj->setBatterySize($size);
}
else
$obj->setBatterySize($size);
$obj->setBatterySize(NULL);
// custom validation for SAP battery
$sap = $em->getRepository(SAPBattery::class)
->find($req->request->get('sap_battery'));
if (empty($sap))
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
// check if sap battery is blank
$sap_battery = $req->request->get('sap_battery');
if (!empty($sap_battery))
{
$sap = $em->getRepository(SAPBattery::class)
->find($req->request->get('sap_battery'));
if (empty($sap))
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
else
$obj->setSAPBattery($sap);
}
else
$obj->setSAPBattery($sap);
$obj->setSAPBattery(NULL);
// validate
$errors = $validator->validate($obj);
@ -234,6 +254,28 @@ class WarrantyController extends Controller
$em->persist($obj);
$em->flush();
// log warranty creation
$action = 'create';
$user_id = $this->getUser()->getUsername();
$source = WarrantySource::ADMIN_PANEL;
$log_data = [
'serial' => $req->request->get('serial'),
'warranty_class' => $req->request->get('warranty_class'),
'first_name' => $req->request->get('first_name'),
'last_name' => $req->request->get('last_name'),
'mobile_number' => $req->request->get('mobile_number'),
'date_purchase' => $req->request->get('date_purchase'),
'claim_from' => $req->request->get('claim_from'),
'status' => $req->request->get('status'),
'date_claim' => $req->request->get('date_claim'),
'date_expire' => $req->request->get('date_expire'),
'battery_model' => $req->request->get('battery_model'),
'battery_size' => $req->request->get('battery_size'),
'sap_battery' => $req->request->get('sap_battery'),
'plate_number' => $req->request->get('plate_number'),
];
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
// return successful response
return $this->json([
'success' => 'Changes have been saved!'
@ -303,31 +345,49 @@ class WarrantyController extends Controller
}
// custom validation for battery model
$model = $em->getRepository(BatteryModel::class)
->find($req->request->get('battery_model'));
if (empty($model))
$error_array['battery_model'] = 'Invalid model selected.';
// check if battery model is blank
$bmodel = $req->request->get('battery_model');
if (!empty($bmodel))
{
$model = $em->getRepository(BatteryModel::class)
->find($req->request->get('battery_model'));
if (empty($model))
$error_array['battery_model'] = 'Invalid model selected.';
else
$obj->setBatteryModel($model);
}
else
$obj->setBatteryModel($model);
$obj->setBatteryModel(NULL);
// custom validation for battery size
$size = $em->getRepository(BatterySize::class)
->find($req->request->get('battery_size'));
if (empty($size))
$error_array['battery_size'] = 'Invalid size selected.';
// check if battery size is blank
$bsize = $req->request->get('battery_size');
if (!empty($bsize))
{
$size = $em->getRepository(BatterySize::class)
->find($req->request->get('battery_size'));
if (empty($size))
$error_array['battery_size'] = 'Invalid size selected.';
else
$obj->setBatterySize($size);
}
else
$obj->setBatterySize($size);
$obj->setBatterySize(NULL);
// custom validation for SAP battery
$sap = $em->getRepository(SAPBattery::class)
->find($req->request->get('sap_battery'));
if (empty($sap))
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
// check if sap battery is blank
$sap_battery = $req->request->get('sap_battery');
if (!empty($sap_battery))
{
$sap = $em->getRepository(SAPBattery::class)
->find($req->request->get('sap_battery'));
if (empty($sap))
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
else
$obj->setSAPBattery($sap);
}
else
$obj->setSAPBattery($sap);
$obj->setSAPBattery(NULL);
// validate
$errors = $validator->validate($obj);
@ -599,7 +659,11 @@ class WarrantyController extends Controller
// error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number);
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
$user_id = $this->getUser()->getUsername();
$source = WarrantySource::BULK_UPLOAD;
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class,
$user_id, $source);
}
}

View file

@ -73,14 +73,14 @@ class Warranty
// battery model
/**
* @ORM\ManyToOne(targetEntity="BatteryModel", inversedBy="warranties")
* @ORM\JoinColumn(name="bty_model_id", referencedColumnName="id")
* @ORM\JoinColumn(name="bty_model_id", referencedColumnName="id", nullable=true)
*/
protected $bty_model;
// battery size
/**
* @ORM\ManyToOne(targetEntity="BatterySize", inversedBy="warranties")
* @ORM\JoinColumn(name="bty_size_id", referencedColumnName="id")
* @ORM\JoinColumn(name="bty_size_id", referencedColumnName="id", nullable=true)
*/
protected $bty_size;
@ -371,7 +371,7 @@ class Warranty
return $this->mobile_number;
}
public function setBatteryModel(BatteryModel $model)
public function setBatteryModel(BatteryModel $model = null)
{
$this->bty_model = $model;
return $this;
@ -382,7 +382,7 @@ class Warranty
return $this->bty_model;
}
public function setBatterySize(BatterySize $size)
public function setBatterySize(BatterySize $size = null)
{
$this->bty_size = $size;
return $this;
@ -393,7 +393,7 @@ class Warranty
return $this->bty_size;
}
public function setSAPBattery(SAPBattery $sap_bty)
public function setSAPBattery(SAPBattery $sap_bty = null)
{
$this->sap_bty = $sap_bty;
return $this;

View file

@ -0,0 +1,164 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use DateTime;
/**
* @ORM\Entity
* @ORM\Table(name="warranty_api_log")
*/
class WarrantyAPILog
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// date created
/**
* @ORM\Column(type="datetime")
*/
protected $date_create;
// user that created warranty
/**
* @ORM\Column(type="string", length=32)
*/
protected $api_user;
// data sent
/**
* @ORM\Column(type="json")
*/
protected $all_data;
// errors
/**
* @ORM\Column(type="array", nullable=true)
*/
protected $errors;
// action
/**
* @ORM\Column(type="string", length=20)
*/
protected $action;
// source
/**
* @ORM\Column(type="string", length=30)
*/
protected $source;
public function __construct()
{
$this->date_create = new DateTime();
$this->errors = new ArrayCollection();
$this->all_data = [];
$this->action = '';
$this->source = '';
}
public function getID()
{
return $this->id;
}
public function setDateCreate(DateTime $date_create)
{
$this->date_create = $date_create;
return $this;
}
public function getDateCreate()
{
return $this->date_create;
}
public function setApiUser($api_user)
{
$this->api_user = $api_user;
return $this;
}
public function getApiUser()
{
return $this->api_user;
}
public function addAllData($id, $value)
{
$this->all_data[$id] = $value;
return $this;
}
public function setAllData($all_data)
{
$this->all_data = $all_data;
return $this;
}
public function getAllData($id)
{
// return null if we don't have it
if (!isset($this->all_data[$id]))
return null;
return $this->all_data[$id];
}
public function getErrors()
{
return $this->errors;
}
public function setErrors(array $errors)
{
$this->errors = new ArrayCollection();
foreach ($errors as $error)
{
$this->errors->add($error);
}
return $this;
}
public function clearErrors()
{
$this->errors = new ArrayCollection();
return $this;
}
public function setAction($action)
{
$this->action = $action;
return $this;
}
public function getAction()
{
return $this->action;
}
public function setSource($source)
{
$this->source = $source;
return $this;
}
public function getSource()
{
return $this->source;
}
}

View file

@ -46,9 +46,16 @@ class WarrantySerial
*/
protected $source;
// other information
/**
* @ORM\Column(type="json")
*/
protected $meta_info;
public function __construct()
{
$this->date_create = new DateTime();
$this->meta_info = [];
}
public function setID($id)
@ -99,4 +106,19 @@ class WarrantySerial
{
return $this->source;
}
public function addMetaInfo($id, $value)
{
$this->meta_info[$id] = $value;
return $this;
}
public function getMetaInfo($id)
{
// return null if we don't have it
if (!isset($this->meta_info[$id]))
return null;
return $this->meta_info[$id];
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace App\Ramcar;
class WarrantySource extends NameValue
{
const CAPI = 'capi';
const RAPI = 'rapi';
const ADMIN_PANEL = 'admin_panel';
const BULK_UPLOAD = 'bulk_upload';
const MOBILE = 'mobile';
const COMMAND = 'command';
const COLLECTION = [
'capi' => 'Third Party API',
'rapi' => 'Rider API',
'admin_panel' => 'Admin Panel',
'bulk_upload' => 'Bulk Upload',
'mobile' => 'Mobile API',
'command' => 'Command',
];
}

View file

@ -40,6 +40,7 @@ use App\Ramcar\JORejectionReason;
use App\Ramcar\CustomerNotWaitReason;
use App\Ramcar\NoTradeInReason;
use App\Ramcar\WillingToWaitContent;
use App\Ramcar\WarrantySource;
use App\Service\InvoiceGeneratorInterface;
use App\Service\JobOrderHandlerInterface;
@ -1016,7 +1017,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
}
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
$user_id = $user->getUsername();
$source = WarrantySource::ADMIN_PANEL;
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source);
}
else
error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber());
@ -1451,6 +1454,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// CMB code
public function processOneStepJobOrder(Request $req, $id)
{
// initialize error list

View file

@ -13,6 +13,7 @@ use App\Ramcar\JOEventType;
use App\Ramcar\InvoiceStatus;
use App\Ramcar\ModeOfPayment;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\WarrantySource;
use App\Service\RiderAPIHandlerInterface;
use App\Service\RedisClientProvider;
@ -598,7 +599,10 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
}
}
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
// for riders, use rider session id
$user_id = $this->session->getID();
$source = WarrantySource::RAPI;
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source);
}
// send mqtt event (fulfilled)

View file

@ -0,0 +1,36 @@
<?php
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\WarrantyAPILog;
class WarrantyAPILogger
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function logWarrantyInfo($log_data, $error, $user_id, $action, $source)
{
$log_entry = new WarrantyAPILog();
$err_aray = [];
$err_array[] = $error;
$log_entry->setApiUser($user_id)
->setErrors($err_array)
->setAllData($log_data)
->setAction($action)
->setSource($source);
$this->em->persist($log_entry);
$this->em->flush();
}
}

View file

@ -11,6 +11,8 @@ use App\Entity\SAPBattery;
use App\Entity\BatteryModel;
use App\Entity\CustomerVehicle;
use App\Service\WarrantyAPILogger;
use App\Ramcar\WarrantyClass;
use DateTime;
@ -19,18 +21,25 @@ use DateInterval;
class WarrantyHandler
{
protected $em;
protected $logger;
public function __construct(EntityManagerInterface $em)
public function __construct(EntityManagerInterface $em, WarrantyAPILogger $logger)
{
$this->em = $em;
$this->logger = $logger;
}
public function createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number,
$batt_list, DateTime $date_purchase, $warranty_class)
$batt_list, DateTime $date_purchase, $warranty_class, $user_id, $source)
{
// new warranty
$warranty = new Warranty();
$bmodel_name = '';
$bsize_name ='';
$sap_batt_id = '';
foreach ($batt_list as $battery)
{
// get the battery model and battery size
@ -43,10 +52,12 @@ class WarrantyHandler
if ($bty_model != null)
{
$warranty->setBatteryModel($bty_model);
$bmodel_name = $bty_model->getName();
}
if ($bty_size != null)
{
$warranty->setBatterySize($bty_size);
$bsize_name = $bty_size->getName();
}
$sap_code = $battery->getSAPCode();
@ -57,6 +68,7 @@ class WarrantyHandler
if ($sap_battery != null)
{
$warranty->setSAPBattery($sap_battery);
$sap_batt_id = $sap_battery->getID();
}
}
}
@ -87,6 +99,23 @@ class WarrantyHandler
$this->em->persist($warranty);
$this->em->flush();
// log warranty creation
$action = 'create';
$log_data = [
'serial' => $serial,
'warranty_class' => $warranty_class,
'first_name' => $first_name,
'last_name' => $last_name,
'mobile_number' => $mobile_number,
'date_purchase' => $date_purchase->format('d-M-y'),
'date_expire' => $date_expire->format('d-M-y'),
'battery_model' => $bmodel_name,
'battery_size' => $bsize_name,
'sap_battery' => $sap_batt_id,
'plate_number' => $plate_number,
];
$this->logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
// update customer vehicle with warranty info
$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);

View file

@ -4,7 +4,7 @@
{% set cust = jo.getCustomer %}
{% set cv = jo.getCustomerVehicle %}
<br>
<a href="{{ url('jo_onestep_edit_form', {'id': jo.getID}) }}">Job Order #{{ jo.getID }}</a><br>
<a href="{{ url('jo_open_edit_form', {'id': jo.getID}) }}">Job Order #{{ jo.getID }}</a><br>
{{ jo.getServiceTypeName }}<br>
{{ jo.getStatusText }}<br><br>
{{ cust.getNameDisplay }}<br>
@ -17,7 +17,7 @@
{% set customer = job_order.getCustomer %}
{% set cust_vehicle = job_order.getCustomerVehicle %}
<br>
<a href="{{ url('jo_onestep_edit_form', {'id': job_order.getID}) }}">Job Order #{{ job_order.getID }}</a><br>
<a href="{{ url('jo_open_edit_form', {'id': job_order.getID}) }}">Job Order #{{ job_order.getID }}</a><br>
{{ customer.getNameDisplay }}<br>
{{ cust_vehicle.getPlateNumber }}
{% endfor %}

View file

@ -0,0 +1,58 @@
<?php
// NOTE: reference: https://github.com/Azure/azure-storage-php/blob/master/samples/BlobSamples.php
require_once(__DIR__ . '/../../vendor/autoload.php');
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
//$blob_url = 'https://popappshopprodstorage.blob.core.windows.net/warranty';
//$sas_token = 'sp=r&st=2021-03-18T08:26:36Z&se=2021-04-29T16:26:36Z&spr=https&sv=2020-02-10&sr=c&sig=Rwl3aCNThXEzuPjNB9sTvZzsx84ULDylyS1WtPwgyzg%3D';
$blob_url = 'https://popappshopprodstorage.blob.core.windows.net';
//$sas_token = 'sp=r&st=2021-03-20T17:09:13Z&se=2021-04-01T01:09:13Z&spr=https&sv=2020-02-10&sr=c&sig=pU2fxj6eXALfGTTrsmaJ7W0QtdstyR88Xs5lvMJ35xQ%3D';
$sas_token = 'sp=r&st=2021-04-13T03:48:30Z&se=2022-04-01T11:48:30Z&spr=https&sv=2020-02-10&sr=c&sig=L6VDl40qRXhQb7w8JVkj3r7x2Xkt72pQaQ8AH2M5CRk%3D';
$conn_string = "BlobEndpoint=$blob_url;\nSharedAccessSignature=$sas_token";
$blob_client = BlobRestProxy::createBlobService($conn_string);
// get start date from argument: 04-01-21 format
$start_date = $argv[1];
$current_date = new DateTime();
$end_date = $current_date->format('m-d-y');
$flag_done_processing = false;
$proc_date = $start_date;
while (!$flag_done_processing) {
$filename = 'warrantylogs' . $proc_date . '.csv';
echo $filename, PHP_EOL;
try {
// NOTE: via download blob
$res = $blob_client->getBlob('warranty', $filename);
// print_r($res);
file_put_contents("/tmp/output.txt", $res->getContentStream(), FILE_APPEND);
} catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
// change proc_date to next day
$next_date = DateTime::createFromFormat('m-d-y', $proc_date);
$next_date->modify('+1 day');
$proc_date = $next_date->format('m-d-y');
if ($end_date == $proc_date) {
$flag_done_processing = true;
}
}

View file

@ -0,0 +1,53 @@
<?php
// NOTE: reference: https://github.com/Azure/azure-storage-php/blob/master/samples/BlobSamples.php
require_once(__DIR__ . '/../../vendor/autoload.php');
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
//$blob_url = 'https://popappshopprodstorage.blob.core.windows.net/warranty';
//$sas_token = 'sp=r&st=2021-03-18T08:26:36Z&se=2021-04-29T16:26:36Z&spr=https&sv=2020-02-10&sr=c&sig=Rwl3aCNThXEzuPjNB9sTvZzsx84ULDylyS1WtPwgyzg%3D';
$blob_url = 'https://popappshopprodstorage.blob.core.windows.net';
//$sas_token = 'sp=r&st=2021-03-20T17:09:13Z&se=2021-04-01T01:09:13Z&spr=https&sv=2020-02-10&sr=c&sig=pU2fxj6eXALfGTTrsmaJ7W0QtdstyR88Xs5lvMJ35xQ%3D';
$sas_token = 'sp=r&st=2021-04-13T03:48:30Z&se=2022-04-01T11:48:30Z&spr=https&sv=2020-02-10&sr=c&sig=L6VDl40qRXhQb7w8JVkj3r7x2Xkt72pQaQ8AH2M5CRk%3D';
$conn_string = "BlobEndpoint=$blob_url;\nSharedAccessSignature=$sas_token";
$blob_client = BlobRestProxy::createBlobService($conn_string);
$current_date = new DateTime();
$current_date->modify("-1 day");
$date = $current_date->format('m-d-y');
$filename = 'warrantylogs' . $date . '.csv';
//print_r($filename);
try {
// NOTE: via download blob
$res = $blob_client->getBlob('warranty', $filename);
// print_r($res);
file_put_contents("/tmp/output.txt", $res->getContentStream());
} catch (Exception $e) {
file_put_contents("/tmp/serial_download_error.txt", $filename . "\n" . $e->getMessage() . "\n" . "\n", FILE_APPEND);
}
/*
// NOTE: getting via url
echo $blob_client->getPsrPrimaryUri() . "\n";
$url = $blob_client->getPsrPrimaryUri() . '?' . $sas_token;
$url = $blob_url . '?' . $sas_token;
file_put_contents('output.txt', fopen($url, 'r'));
*/

View file

@ -10,8 +10,7 @@ $pass = $argv[4];
$db = new PDO($dsn, $user, $pass);
// prepared statement
$sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source) values (:serial, :sku, :date_create, :source)');
$sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source, meta_info) values (:serial, :sku, :date_create, :source, :meta_info)');
// go through rows
$counter = 0;
@ -25,16 +24,41 @@ while (($row = fgetcsv($csv)) !== false)
continue;
}
/*
$serial = trim(strtoupper($row[0]));
$sku = trim($row[1]);
$date_create = $row[2];
$ref_id = $row[3];
$ref_id = $row[3]; */
// sample of line in output file:
// serial number, sku, dispatch status, created date, inventory status, category id, category name
// CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF
$serial = trim(strtoupper($row[0]));
$sku = trim($row[1]);
$dispatch_status = trim($row[2]);
$date_create = $row[3];
$inventory_status = trim($row[4]);
$cat_id = trim($row[5]);
$cat_name = trim($row[6]);
$meta_info = [
'dispatch_status' => $dispatch_status,
'inventory_status' => $inventory_status,
'category_id' => $cat_id,
'category_name' => $cat_name,
];
$info = json_encode($meta_info);
if ($sku == 'N/A')
$sku = null;
$res = $sth->execute([
':serial' => $serial,
':sku' => $sku,
':date_create' => $date_create,
':source' => $source
':source' => $source,
':meta_info' => $info,
]);
if (!$res)

Binary file not shown.

View file

@ -7,20 +7,29 @@ require_once(__DIR__ . '/../../vendor/autoload.php');
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
$blob_url = 'https://popappshopprodstorage.blob.core.windows.net/warranty';
$sas_token = 'sp=r&st=2021-03-18T08:26:36Z&se=2021-04-29T16:26:36Z&spr=https&sv=2020-02-10&sr=c&sig=Rwl3aCNThXEzuPjNB9sTvZzsx84ULDylyS1WtPwgyzg%3D';
//$blob_url = 'https://popappshopprodstorage.blob.core.windows.net/warranty';
//$sas_token = 'sp=r&st=2021-03-18T08:26:36Z&se=2021-04-29T16:26:36Z&spr=https&sv=2020-02-10&sr=c&sig=Rwl3aCNThXEzuPjNB9sTvZzsx84ULDylyS1WtPwgyzg%3D';
$blob_url = 'https://popappshopprodstorage.blob.core.windows.net';
$sas_token = 'sp=r&st=2021-03-20T17:09:13Z&se=2021-04-01T01:09:13Z&spr=https&sv=2020-02-10&sr=c&sig=pU2fxj6eXALfGTTrsmaJ7W0QtdstyR88Xs5lvMJ35xQ%3D';
//$sas_token = 'sp=r&st=2021-03-20T17:09:13Z&se=2021-04-01T01:09:13Z&spr=https&sv=2020-02-10&sr=c&sig=pU2fxj6eXALfGTTrsmaJ7W0QtdstyR88Xs5lvMJ35xQ%3D';
$sas_token = 'sp=r&st=2021-04-13T03:48:30Z&se=2022-04-01T11:48:30Z&spr=https&sv=2020-02-10&sr=c&sig=L6VDl40qRXhQb7w8JVkj3r7x2Xkt72pQaQ8AH2M5CRk%3D';
$conn_string = "BlobEndpoint=$blob_url;\nSharedAccessSignature=$sas_token";
$blob_client = BlobRestProxy::createBlobService($conn_string);
$current_date = new DateTime();
$current_date->modify("-1 day");
$date = $current_date->format('m-d-Y');
$filename = 'warrantylogs' . $date . '.csv';
//print_r($filename);
// NOTE: via download blob
$res = $blob_client->getBlob('warranty', 'Sample Result.csv');
$res = $blob_client->getBlob('warranty', $filename);
// print_r($res);
file_put_contents("output.txt", $res->getContentStream());