<?php
/* vim: set ts=4 sw=4 sts=4 et: */
/**
* Make an Offer Module
*
* @category X-Cart_5_5_Module
* @package MakeAnOffer
* @author CFL Systems, Inc. <support@cflsystems.com>
* @copyright 2023 CFL Systems, Inc. All rights reserved.
* @license License Agreement - https://www.cflsystems.com/software-license-agreement.html
* @link https://www.cflsystems.com/make-an-offer-for-x-cart-5.html
*/
namespace CSI\MakeAnOffer\Model;
use XLite\Core\Converter;
use XLite\Logic\Price;
use XLite\Model\Product;
use XLite\Model\Profile;
use Doctrine\ORM\Mapping as ORM;
/**
* The "MakeAnOffer" model class
*
* @ORM\Entity
* @ORM\Table (name="csi_make_an_offer")
*/
class MakeAnOffer extends \XLite\Model\AEntity
{
/**
* Entry unique ID
*
* @var integer
*
* @ORM\Id
* @ORM\GeneratedValue (strategy="AUTO")
* @ORM\Column (type="integer")
*/
protected $id;
/**
* The product id request applies to
*
* @var Product
*
* @ORM\ManyToOne (targetEntity="XLite\Model\Product", inversedBy="makeAnOffer")
* @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="SET NULL")
*/
protected $product;
/**
* The profile id request applies to
*
* @var Profile
*
* @ORM\ManyToOne (targetEntity="XLite\Model\Profile", inversedBy="makeAnOffer")
* @ORM\JoinColumn (name="profile_id", referencedColumnName="profile_id", onDelete="SET NULL")
*/
protected $profile;
/**
* Customer name
*
* @var string
*
* @ORM\Column (type="string", length=32)
*/
protected $name;
/**
* Customer email
*
* @var string
*
* @ORM\Column (type="string", length=128)
*/
protected $email;
/**
* Customer phone
*
* @var string
*
* @ORM\Column (type="string", length=32)
*/
protected $phone;
/**
* Product name
*
* @var string
*
* @ORM\Column (type="string", length=255)
*/
protected $product_name;
/**
* Product price
*
* @var float
*
* @ORM\Column (type="decimal", precision=14, scale=4)
*/
protected $product_price = 0.0000;
/**
* Offer quantity
*
* @var integer
*
* @ORM\Column (type="integer")
*/
protected $offer_qty = 1;
/**
* Offer price
*
* @var float
*
* @ORM\Column (type="decimal", precision=14, scale=4)
*/
protected $offer_price = 0.0000;
/**
* Remote ip2long
*
* @var integer
*
* @ORM\Column (type="bigint")
*/
protected $ip = 0;
/**
* Request date
*
* @var integer
*
* @ORM\Column (type="integer")
*/
protected $date = 0;
/**
* Status
* A - Accepted
* D - Declined
* P - Pending
*
* @var string
*
* @ORM\Column (type="string", length=1)
*/
protected $status = 'P';
/**
* Admin notes (not visible to customer)
*
* @var text
*
* @ORM\Column (type="text")
*/
protected $admin_notes = '';
/**
* Admin notes (included in email to customer)
*
* @var text
*
* @ORM\Column (type="text")
*/
protected $admin_notes_cust = '';
/**
* Customer notes
*
* @var text
*
* @ORM\Column (type="text")
*/
protected $customer_notes = '';
/**
* Prepare date
*
* @return void
*
* @ORM\PrePersist
*/
public function prepareBeforeCreate()
{
if (!$this->getDate()) {
$this->setDate(Converter::time());
}
}
/**
* Map data to entity columns
*
* @param array $data Array of data
*
* @return self
*/
public function map(array $data)
{
$offer = [];
foreach ($data as $key => $value) {
if ($this->isPropertyExists($key)) {
$offer[$key] = $value;
}
}
return parent::map($offer);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set email
*
* @param string $email
*
* @return self
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set phone
*
* @param string $phone
*
* @return self
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set product_name
*
* @param string $productName
*
* @return self
*/
public function setProductName($productName)
{
$this->product_name = $productName;
return $this;
}
/**
* Get product_name
*
* @return string
*/
public function getProductName()
{
return $this->product_name;
}
/**
* Set product_price
*
* @param float $productPrice
*
* @return self
*/
public function setProductPrice($productPrice)
{
$this->product_price = (float) $productPrice;
return $this;
}
/**
* Get product_price
*
* @return float
*/
public function getProductPrice()
{
return $this->product_price;
}
/**
* Set offer_qty
*
* @param integer $offerQty
*
* @return self
*/
public function setOfferQty($offerQty)
{
$this->offer_qty = (int) $offerQty;
return $this;
}
/**
* Get offer_qty
*
* @return integer
*/
public function getOfferQty()
{
return $this->offer_qty;
}
/**
* Set offer_price
*
* @param float $offerPrice
*
* @return self
*/
public function setOfferPrice($offerPrice)
{
$this->offer_price = (float) $offerPrice;
return $this;
}
/**
* Get offer_price
*
* @return float
*/
public function getOfferPrice()
{
return $this->offer_price;
}
/**
* Set ip
*
* @param string $ip
*
* @return self
*/
public function setIp($ip)
{
$ip = ip2long($ip);
if ($ip == -1 || $ip === false) {
$ip = 0;
}
$this->ip = $ip;
return $this;
}
/**
* Get ip
*
* @return bigint
*/
public function getIp()
{
$ip = long2ip($this->ip);
return empty($ip) ? 0 : $ip;
}
/**
* Set date
*
* @param integer $date
*
* @return self
*/
public function setDate($date)
{
$this->date = (int) $date;
return $this;
}
/**
* Get date
*
* @return integer
*/
public function getDate()
{
return $this->date;
}
/**
* Set status
*
* @param string $status
*
* @return self
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Set admin_notes
*
* @param text $adminNotes
*
* @return self
*/
public function setAdminNotes($adminNotes)
{
$this->admin_notes = $adminNotes;
return $this;
}
/**
* Get admin_notes
*
* @return text
*/
public function getAdminNotes()
{
return $this->admin_notes;
}
/**
* Set admin_notes_cust
*
* @param text $adminNotesCust
*
* @return self
*/
public function setAdminNotesCust($adminNotesCust)
{
$this->admin_notes_cust = $adminNotesCust;
return $this;
}
/**
* Get admin_notes_cust
*
* @return text
*/
public function getAdminNotesCust()
{
return $this->admin_notes_cust;
}
/**
* Set customer_notes
*
* @param text $customerNotes
*
* @return self
*/
public function setCustomerNotes($customerNotes)
{
$this->customer_notes = $customerNotes;
return $this;
}
/**
* Get customer_notes
*
* @return text
*/
public function getCustomerNotes()
{
return $this->customer_notes;
}
/**
* Set product
*
* @param Product $product
*
* @return self
*/
public function setProduct(Product $product = null)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* @return Product
*/
public function getProduct()
{
return $this->product;
}
/**
* Set profile
*
* @param Profile $profile
*
* @return self
*/
public function setProfile(Profile $profile = null)
{
$this->profile = $profile;
return $this;
}
/**
* Get profile
*
* @return Profile
*/
public function getProfile()
{
return $this->profile;
}
/**
* Get net ProductPrice
*
* @return float
*/
public function getNetProductPrice()
{
return Price::getInstance()->apply($this, 'getProductPrice', [], 'net');
}
/**
* Get net OfferPrice
*
* @return float
*/
public function getNetOfferPrice()
{
return Price::getInstance()->apply($this, 'getOfferPrice', [], 'net');
}
}