/**
* File Auto-Generated by the RICADO Gen 4 PHP API Project
*
* Do Not Edit this File Manually!
*/
import BaseModel from '../../../Models/BaseModel';
/**
* Model Class for a Packrun
*
* @class
* @hideconstructor
* @extends BaseModel
*/
class PackrunModel extends BaseModel
{
/**
* PackrunModel Constructor
*
* @protected
* @param {number} siteId The Site ID associated with this Packrun
*/
constructor(siteId)
{
super();
/**
* The Packrun ID
*
* @type {string}
* @public
*/
this.id = "";
/**
* The Packing Line ID this Packrun is associated with
*
* @type {string}
* @public
*/
this.packingLineId = "";
/**
* The Packrun Name
*
* @type {string}
* @public
*/
this.name = "";
/**
* When this Packrun was Created
*
* @type {Date}
* @public
*/
this.createdTimestamp = new Date();
/**
* The Grower Name for this Packrun
*
* @type {string}
* @public
*/
this.growerName = "";
/**
* The Grower Code for this Packrun
*
* @type {string}
* @public
*/
this.growerCode = "";
/**
* The Maturity Area for this Packrun
*
* @type {string}
* @public
*/
this.maturityArea = "";
/**
* When this Packrun was Started
*
* @type {?Date}
* @public
*/
this.startTimestamp = null;
/**
* When this Packrun was Finished
*
* @type {?Date}
* @public
*/
this.finishTimestamp = null;
/**
* The Variety for this Packrun
*
* @type {string}
* @public
*/
this.varietyId = "";
/**
* The Growing Method for this Packrun
*
* @type {?string}
* @public
*/
this.growingMethodId = null;
/**
* The Number of Allocated Bins for this Packrun
*
* @type {number}
* @public
*/
this.allocatedBins = 0;
/**
* The Time Batches for this Packrun
*
* @type {Array<{id: string, timestamp: Date}>}
* @public
*/
this.timeBatches = [];
/**
* The FreshPack Grader ID associated with this Packrun
*
* @type {?number}
* @public
*/
this.freshPackGraderId = null;
/**
* The FreshPack Bin Lot Code associated with this Packrun
*
* @type {?string}
* @public
*/
this.freshPackBinLotCode = null;
/**
* The FreshPack Produce Code associated with this Packrun
*
* @type {?string}
* @public
*/
this.freshPackProduceCode = null;
/**
* Whether the Packrun has been deleted
*
* @type {boolean}
* @public
*/
this.deleted = false;
/**
* When the Packrun was last updated
*
* @type {Date}
* @public
*/
this.updateTimestamp = new Date();
/**
* The Site ID associated with this Packrun
*
* @type {number}
* @public
*/
this.siteId = siteId;
}
/**
* Create a new **PackrunModel** from a JSON Object or JSON String
*
* @static
* @public
* @param {Object<string, any>|string} json A JSON Object or JSON String
* @param {number} siteId The Site ID associated with this Packrun
* @return {PackrunModel}
*/
static fromJSON(json, siteId)
{
let model = new PackrunModel(siteId);
/**
* The JSON Object
*
* @type {Object<string, any>}
*/
let jsonObject = {};
if(typeof json === 'string')
{
jsonObject = JSON.parse(json);
}
else if(typeof json === 'object')
{
jsonObject = json;
}
if('id' in jsonObject)
{
model.id = (function(){
if(typeof jsonObject['id'] !== 'string')
{
return String(jsonObject['id']);
}
return jsonObject['id'];
}());
}
if('packingLineId' in jsonObject)
{
model.packingLineId = (function(){
if(typeof jsonObject['packingLineId'] !== 'string')
{
return String(jsonObject['packingLineId']);
}
return jsonObject['packingLineId'];
}());
}
if('name' in jsonObject)
{
model.name = (function(){
if(typeof jsonObject['name'] !== 'string')
{
return String(jsonObject['name']);
}
return jsonObject['name'];
}());
}
if('createdTimestamp' in jsonObject)
{
model.createdTimestamp = (function(){
if(typeof jsonObject['createdTimestamp'] !== 'string')
{
return new Date(String(jsonObject['createdTimestamp']));
}
return new Date(jsonObject['createdTimestamp']);
}());
}
if('growerName' in jsonObject)
{
model.growerName = (function(){
if(typeof jsonObject['growerName'] !== 'string')
{
return String(jsonObject['growerName']);
}
return jsonObject['growerName'];
}());
}
if('growerCode' in jsonObject)
{
model.growerCode = (function(){
if(typeof jsonObject['growerCode'] !== 'string')
{
return String(jsonObject['growerCode']);
}
return jsonObject['growerCode'];
}());
}
if('maturityArea' in jsonObject)
{
model.maturityArea = (function(){
if(typeof jsonObject['maturityArea'] !== 'string')
{
return String(jsonObject['maturityArea']);
}
return jsonObject['maturityArea'];
}());
}
if('startTimestamp' in jsonObject)
{
model.startTimestamp = (function(){
if(jsonObject['startTimestamp'] === null)
{
return null;
}
if(typeof jsonObject['startTimestamp'] !== 'string')
{
return new Date(String(jsonObject['startTimestamp']));
}
return new Date(jsonObject['startTimestamp']);
}());
}
if('finishTimestamp' in jsonObject)
{
model.finishTimestamp = (function(){
if(jsonObject['finishTimestamp'] === null)
{
return null;
}
if(typeof jsonObject['finishTimestamp'] !== 'string')
{
return new Date(String(jsonObject['finishTimestamp']));
}
return new Date(jsonObject['finishTimestamp']);
}());
}
if('varietyId' in jsonObject)
{
model.varietyId = (function(){
if(typeof jsonObject['varietyId'] !== 'string')
{
return String(jsonObject['varietyId']);
}
return jsonObject['varietyId'];
}());
}
if('growingMethodId' in jsonObject)
{
model.growingMethodId = (function(){
if(jsonObject['growingMethodId'] === null)
{
return null;
}
if(typeof jsonObject['growingMethodId'] !== 'string')
{
return String(jsonObject['growingMethodId']);
}
return jsonObject['growingMethodId'];
}());
}
if('allocatedBins' in jsonObject)
{
model.allocatedBins = (function(){
if(typeof jsonObject['allocatedBins'] !== 'number')
{
return Number.isInteger(Number(jsonObject['allocatedBins'])) ? Number(jsonObject['allocatedBins']) : Math.floor(Number(jsonObject['allocatedBins']));
}
return Number.isInteger(jsonObject['allocatedBins']) ? jsonObject['allocatedBins'] : Math.floor(jsonObject['allocatedBins']);
}());
}
if('timeBatches' in jsonObject)
{
model.timeBatches = (function(){
if(Array.isArray(jsonObject['timeBatches']) !== true)
{
return [];
}
return jsonObject['timeBatches'].map((timeBatchesItem) => {
return (function(){
let timeBatchesItemObject = {};
if(typeof timeBatchesItem === 'object' && 'id' in timeBatchesItem)
{
timeBatchesItemObject.id = (function(){
if(typeof timeBatchesItem.id !== 'string')
{
return String(timeBatchesItem.id);
}
return timeBatchesItem.id;
}());
}
else
{
timeBatchesItemObject.id = "";
}
if(typeof timeBatchesItem === 'object' && 'timestamp' in timeBatchesItem)
{
timeBatchesItemObject.timestamp = (function(){
if(typeof timeBatchesItem.timestamp !== 'string')
{
return new Date(String(timeBatchesItem.timestamp));
}
return new Date(timeBatchesItem.timestamp);
}());
}
else
{
timeBatchesItemObject.timestamp = new Date();
}
return timeBatchesItemObject;
}());
});
}());
}
if('freshPackGraderId' in jsonObject)
{
model.freshPackGraderId = (function(){
if(jsonObject['freshPackGraderId'] === null)
{
return null;
}
if(typeof jsonObject['freshPackGraderId'] !== 'number')
{
return Number.isInteger(Number(jsonObject['freshPackGraderId'])) ? Number(jsonObject['freshPackGraderId']) : Math.floor(Number(jsonObject['freshPackGraderId']));
}
return Number.isInteger(jsonObject['freshPackGraderId']) ? jsonObject['freshPackGraderId'] : Math.floor(jsonObject['freshPackGraderId']);
}());
}
if('freshPackBinLotCode' in jsonObject)
{
model.freshPackBinLotCode = (function(){
if(jsonObject['freshPackBinLotCode'] === null)
{
return null;
}
if(typeof jsonObject['freshPackBinLotCode'] !== 'string')
{
return String(jsonObject['freshPackBinLotCode']);
}
return jsonObject['freshPackBinLotCode'];
}());
}
if('freshPackProduceCode' in jsonObject)
{
model.freshPackProduceCode = (function(){
if(jsonObject['freshPackProduceCode'] === null)
{
return null;
}
if(typeof jsonObject['freshPackProduceCode'] !== 'string')
{
return String(jsonObject['freshPackProduceCode']);
}
return jsonObject['freshPackProduceCode'];
}());
}
if('deleted' in jsonObject)
{
model.deleted = (function(){
if(typeof jsonObject['deleted'] !== 'boolean')
{
return Boolean(jsonObject['deleted']);
}
return jsonObject['deleted'];
}());
}
if('updateTimestamp' in jsonObject)
{
model.updateTimestamp = (function(){
if(typeof jsonObject['updateTimestamp'] !== 'string')
{
return new Date(String(jsonObject['updateTimestamp']));
}
return new Date(jsonObject['updateTimestamp']);
}());
}
return model;
}
}
export default PackrunModel;
source