<?php
namespace Plugin\np42\Entity;
use Doctrine\ORM\Mapping as ORM;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Order;
use Plugin\np42\Service\PaymentApi\Cancel;
use Plugin\np42\Service\PaymentApi\Capture;
use Plugin\np42\Service\PaymentApi\Change;
use Plugin\np42\Service\PaymentApi\Register;
/**
* OrderNp
*
* @ORM\Table(name="plg_np42_order_np")
* @ORM\Entity(repositoryClass="Plugin\np42\Repository\OrderNpRepository")
*/
class OrderNp
{
/**
* NP後払いステータス
*/
const NP_STATUS_OK = '00';
const NP_STATUS_HOLD = '10';
const NP_STATUS_NG = '20';
const NP_STATUS_BEFORE = '40';
const NP_STATUS_REVIEW = '550'; // すでに、出荷報告済み:50で使用しているため別の番号を割り振る
const NP_STATUS_SEND = '50';
const NP_STATUS_CANCEL = '60';
const NP_STATUS_NONE = '01';
const NP_STATUS_OK_NAME = "審査OK";
const NP_STATUS_HOLD_NAME = "保留";
const NP_STATUS_NG_NAME = "審査NG";
const NP_STATUS_BEFORE_NAME = "審査前";
const NP_STATUS_REVIEW_NAME = "審査中";
const NP_STATUS_SEND_NAME = "出荷報告済";
const NP_STATUS_CANCEL_NAME = "キャンセル済";
const NP_STATUS_NONE_NAME = '取引未完了';
const NP_STATUS_LIST = [
self::NP_STATUS_OK => self::NP_STATUS_OK_NAME,
self::NP_STATUS_HOLD => self::NP_STATUS_HOLD_NAME,
self::NP_STATUS_NG => self::NP_STATUS_NG_NAME,
self::NP_STATUS_BEFORE => self::NP_STATUS_BEFORE_NAME,
self::NP_STATUS_REVIEW => self::NP_STATUS_REVIEW_NAME,
self::NP_STATUS_SEND => self::NP_STATUS_SEND_NAME,
self::NP_STATUS_CANCEL => self::NP_STATUS_CANCEL_NAME,
self::NP_STATUS_NONE => self::NP_STATUS_NONE_NAME,
];
/**
* @var int
*
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var Eccube\Entity\Order
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderNp")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="order_id", referencedColumnName="id")
* })
*/
private $Order;
/**
* @var int $np_status_id NP後払いステータスID
* @ORM\Column(name="np_status_id", type="text", options={"default":"00", "comment":"NP後払いステータスID"})
*/
private $np_status_id = '';
/**
* @var string
* @ORM\Column(name="shop_code", type="text", options={"default":"", "comment": "加盟店コード"})
*/
private $shop_code = '';
/**
* @var string
* @ORM\Column(name="shop_transaction_no", type="text", options={"default":"", "comment": "加盟店取引ID 半角英数字"})
*/
private $shop_transaction_no = '';
/**
* @var string
* @ORM\Column(name="transaction_id", type="text", options={"default":"", "comment": "取引ID format:YYMMDDXXXXX"})
*/
private $transaction_id = '';
/**
* @var string $authorization_result 与信結果
* @ORM\Column(name="authorization_result", type="text", options={"default":"", "comment": "与信結果"})
*/
private $authorization_result = '';
/**
* @var string $authorization_result_ng_reason 与信NG事由
* @ORM\Column(name="authorization_result_ng_reason", type="text", options={"default":"", "comment": "与信NG事由"})
*/
private $authorization_result_ng_reason = '';
/**
* @var string
* @ORM\Column(name="authori_hold", type="text", options={"default":"", "comment": "与信保留事由"})
*/
private $authori_hold = '';
/**
* @var string $amount atone顧客請求金額
* @ORM\Column(name="amount", type="integer", options={"default":0, "comment": "顧客請求金額"})
*/
private $amount;
/**
* @var string $np_settlement_type 請求書区分
* @ORM\Column(name="np_settlement_type", type="text", options={"default":"", "comment": "請求書区分"})
*/
private $np_settlement_type = '';
/**
* md5でハッシュ化された受注情報
*
* @var string $order_np_detail_md5
*
* @ORM\Column(name="order_np_detail_md5", type="text", length=65532, nullable=true, options={"default":"", "comment": "NP後払い md5でハッシュ化された受注情報"})
*/
private $order_np_detail_md5 = '';
/**
* @var string $order_diff
*
* @ORM\Column(name="order_diff", type="text", nullable=true, options={"default":"", "comment": "NP後払い 差分情報"})
*/
private $order_diff = '';
/**
* @var \DateTime
*
* @ORM\Column(name="create_date", type="datetimetz", options={"comment": "作成日時"})
*/
private $create_date;
/**
* @var \DateTime
*
* @ORM\Column(name="update_date", type="datetimetz", options={"comment": "更新日時"})
*/
private $update_date;
public function getOrder(): ?Order
{
return $this->Order;
}
public function setOrder(Order $Order)
{
$this->Order = $Order;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getShopCode(): ?string
{
return $this->shop_code;
}
public function setShopCode(string $shop_code): self
{
$this->shop_code = $shop_code;
return $this;
}
public function getShopTransactionNo(): ?string
{
return $this->shop_transaction_no;
}
public function setShopTransactionNo(string $shop_transaction_no): self
{
$this->shop_transaction_no = $shop_transaction_no;
return $this;
}
public function getTransactionId(): ?string
{
return $this->transaction_id;
}
public function setTransactionId(string $transaction_id): self
{
$this->transaction_id = $transaction_id;
return $this;
}
public function getAuthorizationResult(): ?string
{
return $this->authorization_result;
}
public function setAuthorizationResult(string $authorization_result): self
{
$this->authorization_result = $authorization_result;
return $this;
}
public function getAuthorizationResultNgReason(): ?string
{
return $this->authorization_result_ng_reason;
}
public function setAuthorizationResultNgReason(string $authorization_result_ng_reason): self
{
$this->authorization_result_ng_reason = $authorization_result_ng_reason;
return $this;
}
public function getAuthoriHoldToArray(): array
{
if (empty($this->authori_hold)) {
return [];
}
return json_decode($this->authori_hold, JSON_UNESCAPED_UNICODE);
}
public function getAuthoriHold(): ?string
{
return $this->authori_hold;
}
public function setAuthoriHold(string $authori_hold): self
{
$this->authori_hold = $authori_hold;
return $this;
}
/**
* @return string
*/
public function getNpStatusId(): string
{
return $this->np_status_id;
}
/**
* @param string $np_status_id
*/
public function setNpStatusId(string $np_status_id): self
{
$this->np_status_id = $np_status_id;
return $this;
}
/**
* @return string
*/
public function getAmount(): string
{
return $this->amount;
}
/**
* @param string $amount
*/
public function setAmount(string $amount): self
{
$this->amount = $amount;
return $this;
}
/**
* @return string
*/
public function getNpSettlementType(): string
{
return $this->np_settlement_type;
}
/**
* @param string $np_settlement_type
*/
public function setNpSettlementType(string $np_settlement_type): self
{
$this->np_settlement_type = $np_settlement_type;
return $this;
}
/**
* Set createDate.
*
* @param \DateTime $createDate
*
* @return $this
*/
public function setCreateDate($createDate): self
{
$this->create_date = $createDate;
return $this;
}
/**
* Get createDate.
*
* @return \DateTime
*/
public function getCreateDate()
{
return $this->create_date;
}
/**
* Set updateDate.
*
* @param \DateTime $updateDate
*
* @return $this
*/
public function setUpdateDate($updateDate): self
{
$this->update_date = $updateDate;
return $this;
}
/**
* Get updateDate.
*
* @return \DateTime
*/
public function getUpdateDate()
{
return $this->update_date;
}
/**
* @return string
*/
public function getOrderNpDetailMd5(): string
{
return $this->order_np_detail_md5;
}
/**
* @param string $order_np_detail_md5
*/
public function setOrderNpDetailMd5(string $order_np_detail_md5): self
{
$this->order_np_detail_md5 = $order_np_detail_md5;
return $this;
}
/**
* @return string|null
*/
public function getOrderDiff(): ?string
{
return $this->order_diff;
}
/**
* @param string|null $order_diff
*/
public function setOrderDiff(?string $order_diff): self
{
$this->order_diff = $order_diff;
return $this;
}
public function getCancelRequestAction(): string
{
// 取引キャンセル
if ($this->getNpStatusId() != self::NP_STATUS_CANCEL
&& $this->getNpStatusId() != self::NP_STATUS_NONE) {
return Cancel::__REQUEST_ACTION;
}
return '';
}
public function getSubmitRequestAction(): string
{
/** * @var \Eccube\Entity\Order $Order */
$Order = $this->getOrder();
// 発送伝票番号があるか
$is_tracking_number = true;
/** @var \Eccube\Entity\Shipping $Shipping */
foreach ($Order->getShippings() as $Shipping) {
if (is_null($Shipping->getTrackingNumber()) || $Shipping->getTrackingNumber() === '') {
$is_tracking_number = false;
}
}
// 取引登録
if (self::NP_STATUS_NONE === $this->getNpStatusId()
&& $Order->getOrderStatus()->getId() != OrderStatus::CANCEL
) {
return Register::__REQUEST_ACTION;
}
// 売上確定 トラッキングナンバーがある。差分がない。発送済み。出荷報告済・キャンセル済以外。
if ($is_tracking_number
&& $this->getOrderNpDetailMd5() === $Order->getOrderNpDetailMd5()
&& $Order->getOrderStatus()->getId() == OrderStatus::DELIVERED
&& $this->getNpStatusId() != self::NP_STATUS_SEND
&& $this->getNpStatusId() != self::NP_STATUS_CANCEL
) {
return Capture::__REQUEST_ACTION;
}
// 取引更新
if ($this->getOrderNpDetailMd5() != $Order->getOrderNpDetailMd5()
&& $Order->getOrderStatus()->getId() != OrderStatus::CANCEL
&& $this->getNpStatusId() != self::NP_STATUS_NONE
&& $this->getNpStatusId() != self::NP_STATUS_SEND
&& $this->getNpStatusId() != self::NP_STATUS_CANCEL
) {
return Change::__REQUEST_ACTION;
}
return '';
}
}