drafting sales billing view

This commit is contained in:
Dennis Eichhorn 2021-01-31 17:19:24 +01:00
parent 6ff583ebed
commit c06f855d74
6 changed files with 84 additions and 53 deletions

View File

@ -291,21 +291,27 @@
"type": "INT",
"null": false
},
"billing_out_element_purchase_price": {
"name": "billing_out_element_purchase_price",
"type": "INT",
"billing_out_element_single_salesprice_net": {
"name": "billing_out_element_single_salesprice_net",
"type": "BIGINT",
"null": true,
"default": null
},
"billing_out_element_price_single": {
"name": "billing_out_element_price_single",
"type": "INT",
"billing_out_element_single_purchaseprice_net": {
"name": "billing_out_element_single_purchaseprice_net",
"type": "BIGINT",
"null": true,
"default": null
},
"billing_out_element_price_total": {
"name": "billing_out_element_price_total",
"type": "INT",
"billing_out_element_total_salesprice_net": {
"name": "billing_out_element_total_salesprice_net",
"type": "BIGINT",
"null": true,
"default": null
},
"billing_out_element_total_purchaseprice_net": {
"name": "billing_out_element_total_purchaseprice_net",
"type": "BIGINT",
"null": true,
"default": null
},

View File

@ -30,6 +30,7 @@ use phpOMS\Message\ResponseAbstract;
use phpOMS\Model\Message\FormValidation;
use phpOMS\Utils\Parser\Markdown\Markdown;
use Modules\ItemManagement\Models\ItemMapper;
use phpOMS\Localization\Money;
/**
* Billing class.
@ -138,6 +139,10 @@ final class ApiController extends Controller
$element = $this->createBillElementFromRequest($request, $response, $data);
$this->createModel($request->header->account, $element, BillElementMapper::class, 'bill_element', $request->getOrigin());
$bill = $this->updateBillWithBillElement($element, 1);
$this->updateModel($request->header->account, $element, BillMapper::class, 'bill_element', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Bill element', 'Bill element successfully created.', $element);
}
@ -163,12 +168,41 @@ final class ApiController extends Controller
// @todo: which item name should be stored in the database? server language (problem for international company with subsidiaries)? customer default language/customer invoice language?
$element->itemNumber = $item->number;
$element->itemName = $item->getL11n('name1')->description;
$element->quantity = $request->getData('quantity', 'int');;
$element->quantity = $request->getData('quantity', 'int');
$element->singleSalesPriceNet = new Money($request->getData('singlesalespricenet', 'int') ?? $item->salesPrice->getInt());
$element->totalSalesPriceNet = clone $element->singleSalesPriceNet;
$element->totalSalesPriceNet->mult($element->quantity);
$element->singlePurchasePriceNet = new Money($item->purchasePrice->getInt());
$element->totalPurchasePriceNet = clone $element->singlePurchasePriceNet;
$element->totalPurchasePriceNet->mult($element->quantity);
}
return $element;
}
/**
* Method to create a wiki entry from request.
*
* @param BillElement $element Bill element
* @param int $type Change type (0 = update, -1 = remove, +1 = add)
*
* @return BillElement
*
* @since 1.0.0
*/
public function updateBillWithBillElement(BillElement $element, int $type = 1) : Bill
{
$bill = BillMapper::get($element->bill);
if ($type === 1) {
$bill->net->add($element->singleSalesPriceNet);
}
return $bill;
}
/**
* Method to validate wiki entry creation from request
*

View File

@ -193,13 +193,13 @@ class Bill implements \JsonSerializable
private $referralName = '';
public ?Money $net = null;
public Money $net;
public ?Money $gross = null;
public Money $gross;
public ?Money $costs = null;
public Money $costs;
public ?Money $profit = null;
public Money $profit;
private $currency = ISO4217CharEnum::_EUR;

View File

@ -44,11 +44,11 @@ class BillElement implements \JsonSerializable
public string $itemDescription = '';
public int|float $quantity = 0;
public int $quantity = 0;
private $singlePrice = null;
public Money $singleSalesPriceNet;
private $totalPrice = null;
public Money $totalSalesPriceNet;
private $singleDiscountP = null;
@ -62,13 +62,17 @@ class BillElement implements \JsonSerializable
private $totalPriceNet = null;
public Money $singlePurchasePriceNet;
public Money $totalPurchasePriceNet;
private $taxP = null;
private $taxR = 0.0;
private $singlePriceGross = null;
private $singleSalesPriceGross = null;
private $totalPriceGross = null;
private $totalSalesPriceGross = null;
private $event = 0;
@ -76,6 +80,15 @@ class BillElement implements \JsonSerializable
public $bill = 0;
public function __construct()
{
$this->singleSalesPriceNet = new Money();
$this->totalSalesPriceNet = new Money();
$this->singlePurchasePriceNet = new Money();
$this->totalPurchasePriceNet = new Money();
}
/**
* Get id.
*
@ -232,32 +245,6 @@ class BillElement implements \JsonSerializable
return $this->itemDescription;
}
/**
* Set quantity.
*
* @param int|float $quantity Quantity
*
* @return void
*
* @since 1.0.0
*/
public function setQuantity($quantity) : void
{
$this->quantity = $quantity;
}
/**
* Get quantity.
*
* @return int|float
*
* @since 1.0.0
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Set single unit price.
*

View File

@ -41,6 +41,10 @@ final class BillElementMapper extends DataMapperAbstract
'billing_out_element_item_name' => ['name' => 'billing_out_element_item_name', 'type' => 'string', 'internal' => 'itemName'],
'billing_out_element_item_desc' => ['name' => 'billing_out_element_item_desc', 'type' => 'string', 'internal' => 'itemDescription'],
'billing_out_element_quantity' => ['name' => 'billing_out_element_quantity', 'type' => 'int', 'internal' => 'quantity'],
'billing_out_element_single_salesprice_net' => ['name' => 'billing_out_element_single_salesprice_net', 'type' => 'Serializable', 'internal' => 'singleSalesPriceNet'],
'billing_out_element_single_purchaseprice_net' => ['name' => 'billing_out_element_single_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'singlePurchasePriceNet'],
'billing_out_element_total_salesprice_net' => ['name' => 'billing_out_element_total_salesprice_net', 'type' => 'Serializable', 'internal' => 'totalSalesPriceNet'],
'billing_out_element_total_purchaseprice_net' => ['name' => 'billing_out_element_total_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'totalPurchasePriceNet'],
'billing_out_element_bill' => ['name' => 'billing_out_element_bill', 'type' => 'int', 'internal' => 'bill'],
];

View File

@ -134,14 +134,14 @@ echo $this->getData('nav')->render(); ?>
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Invoice'); ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default">
<table class="default" id="invoice-item-list">
<thead>
<tr>
<td>
<td><?= $this->getHtml('Item'); ?>
<td><?= $this->getHtml('Variation'); ?>
<td class="wf-100"><?= $this->getHtml('Name'); ?>
<td><?= $this->getHtml('Quantity'); ?>
<td><?= $this->getHtml('Price'); ?>
<td><?= $this->getHtml('Discount'); ?>
<td><?= $this->getHtml('DiscountP'); ?>
<td><?= $this->getHtml('Bonus'); ?>
@ -150,23 +150,23 @@ echo $this->getData('nav')->render(); ?>
<tbody>
<?php foreach ($elements as $element) : ?>
<tr>
<td><i class="fa fa-plus"></i> <i class="fa fa-chevron-up"></i> <i class="fa fa-chevron-down"></i>
<td><i class="fa fa-plus add"></i> <i class="fa fa-chevron-up order-up"></i> <i class="fa fa-chevron-down order-down"></i>
<td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" value="<?= $element->itemNumber; ?>" required></span>
<td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" required></span>
<td><textarea required><?= $element->itemName; ?></textarea>
<td><input type="number" min="0" value="0" required>
<td><input type="number" min="0" value="<?= $element->quantity ?>" required>
<td><input type="text" value="<?= $element->singleSalesPriceNet->getCurrency(); ?>">
<td><input type="number" min="0">
<td><input type="number" min="0" max="100" step="any">
<td><input type="number" min="0" step="any">
<td><input type="number" min="0" step="any">
<td>
<td><?= $element->totalSalesPriceNet->getCurrency(); ?>
<?php endforeach; ?>
<tr>
<td><i class="fa fa-plus"></i> <i class="fa fa-chevron-up"></i> <i class="fa fa-chevron-down"></i>
<td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" required></span>
<td><i class="fa fa-plus"></i> <i class="fa fa-chevron-up order-up"></i> <i class="fa fa-chevron-down order-down"></i>
<td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" required></span>
<td><textarea required></textarea>
<td><input type="number" min="0" value="0" required>
<td><input type="text">
<td><input type="number" min="0">
<td><input type="number" min="0" max="100" step="any">
<td><input type="number" min="0" step="any">