This commit is contained in:
Dennis Eichhorn 2021-11-29 20:08:13 +01:00
parent 6af2fbaf63
commit 70f2c0887b
9 changed files with 65 additions and 53 deletions

View File

@ -4,8 +4,12 @@ use Mpdf\Mpdf;
/** /**
* @var \phpOMS\Views\View $this * @var \phpOMS\Views\View $this
* @var \Modules\Billing\Models\Bill
*/ */
$bill = $this->getData('bill'); $bill = $this->getData('bill');
/**
* @var \Modules\Billing\Models\BillElement[] $elements
*/
$elements = $bill->getElements(); $elements = $bill->getElements();
$mpdf = new Mpdf([ $mpdf = new Mpdf([
@ -140,7 +144,7 @@ $html .= '
<tr> <tr>
<td class="blanktotal" colspan="3" rowspan="6"></td> <td class="blanktotal" colspan="3" rowspan="6"></td>
<td class="totals">Subtotal:</td> <td class="totals">Subtotal:</td>
<td class="totals cost">' . $bill->net->getCurrency(null) . '</td> <td class="totals cost">' . $bill->netSales->getCurrency(null) . '</td>
</tr> </tr>
<tr> <tr>
<td class="totals">Tax:</td> <td class="totals">Tax:</td>
@ -152,7 +156,7 @@ $html .= '
</tr> </tr>
<tr> <tr>
<td class="totals"><strong>TOTAL:</strong></td> <td class="totals"><strong>TOTAL:</strong></td>
<td class="totals cost"><strong>' . $bill->gross->getCurrency(null) . '</strong></td> <td class="totals cost"><strong>' . $bill->grossSales->getCurrency(null) . '</strong></td>
</tr> </tr>
<tr> <tr>
<td class="totals">Deposit:</td> <td class="totals">Deposit:</td>

View File

@ -361,7 +361,7 @@
"default": null "default": null
}, },
"billing_bill_element_single_grosslistprice": { "billing_bill_element_single_grosslistprice": {
"name": "billing_bill_element_single_netlistprice", "name": "billing_bill_element_single_grosslistprice",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -373,7 +373,7 @@
"default": null "default": null
}, },
"billing_bill_element_total_grosslistprice": { "billing_bill_element_total_grosslistprice": {
"name": "billing_bill_element_total_netlistprice", "name": "billing_bill_element_total_grosslistprice",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -385,7 +385,7 @@
"default": null "default": null
}, },
"billing_bill_element_single_grosssalesprice": { "billing_bill_element_single_grosssalesprice": {
"name": "billing_bill_element_single_netsalesprice", "name": "billing_bill_element_single_grosssalesprice",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -397,7 +397,7 @@
"default": null "default": null
}, },
"billing_bill_element_total_grosssalesprice": { "billing_bill_element_total_grosssalesprice": {
"name": "billing_bill_element_total_netsalesprice", "name": "billing_bill_element_total_grosssalesprice",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -409,7 +409,7 @@
"default": null "default": null
}, },
"billing_bill_element_single_grosspurchaseprice": { "billing_bill_element_single_grosspurchaseprice": {
"name": "billing_bill_element_single_netpurchaseprice", "name": "billing_bill_element_single_grosspurchaseprice",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -421,7 +421,7 @@
"default": null "default": null
}, },
"billing_bill_element_total_grosspurchaseprice": { "billing_bill_element_total_grosspurchaseprice": {
"name": "billing_bill_element_total_netpurchaseprice", "name": "billing_bill_element_total_grosspurchaseprice",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -433,7 +433,7 @@
"default": null "default": null
}, },
"billing_bill_element_single_grossprofit": { "billing_bill_element_single_grossprofit": {
"name": "billing_bill_element_single_netprofit", "name": "billing_bill_element_single_grossprofit",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -445,7 +445,7 @@
"default": null "default": null
}, },
"billing_bill_element_total_grossprofit": { "billing_bill_element_total_grossprofit": {
"name": "billing_bill_element_total_netprofit", "name": "billing_bill_element_total_grossprofit",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
@ -579,7 +579,7 @@
"primary": true, "primary": true,
"autoincrement": true "autoincrement": true
}, },
"billing_bill_note_item": { "billing_bill_note_bill": {
"name": "billing_bill_note_bill", "name": "billing_bill_note_bill",
"type": "INT", "type": "INT",
"null": false, "null": false,

View File

@ -290,8 +290,8 @@ final class ApiController extends Controller
public function updateBillWithBillElement(Bill $bill, BillElement $element, int $type = 1) : Bill public function updateBillWithBillElement(Bill $bill, BillElement $element, int $type = 1) : Bill
{ {
if ($type === 1) { if ($type === 1) {
$bill->net->add($element->singleSalesPriceNet); $bill->netSales->add($element->totalSalesPriceNet);
$bill->costs->add($element->singlePurchasePriceNet); $bill->netCosts->add($element->totalPurchasePriceNet);
} }
return $bill; return $bill;
@ -412,7 +412,7 @@ final class ApiController extends Controller
} }
/** /**
* Api method to create item files * Api method to create bill files
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* @param ResponseAbstract $response Response * @param ResponseAbstract $response Response
@ -427,13 +427,13 @@ final class ApiController extends Controller
public function apiNoteCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void public function apiNoteCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{ {
if (!empty($val = $this->validateNoteCreate($request))) { if (!empty($val = $this->validateNoteCreate($request))) {
$response->set('item_note_create', new FormValidation($val)); $response->set('bill_note_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400; $response->header->status = RequestStatusCode::R_400;
return; return;
} }
$request->setData('virtualpath', '/Modules/Billing/Articles/' . $request->getData('id'), true); $request->setData('virtualpath', '/Modules/Billing/Bills/' . $request->getData('id'), true);
$this->app->moduleManager->get('Editor')->apiEditorCreate($request, $response, $data); $this->app->moduleManager->get('Editor')->apiEditorCreate($request, $response, $data);
if ($response->header->status !== RequestStatusCode::R_200) { if ($response->header->status !== RequestStatusCode::R_200) {
@ -445,7 +445,7 @@ final class ApiController extends Controller
} }
/** /**
* Validate item note create request * Validate bill note create request
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *

View File

@ -479,6 +479,10 @@ class Bill implements \JsonSerializable
*/ */
public function getNumber() : string public function getNumber() : string
{ {
if (empty($this->number)) {
$this->buildNumber();
}
return $this->number; return $this->number;
} }

View File

@ -104,7 +104,7 @@ class BillMapper extends DataMapperAbstract
'mapper' => EditorDocMapper::class, /* mapper of the related object */ 'mapper' => EditorDocMapper::class, /* mapper of the related object */
'table' => 'billing_bill_note', /* table of the related object, null if no relation table is used (many->1) */ 'table' => 'billing_bill_note', /* table of the related object, null if no relation table is used (many->1) */
'external' => 'billing_bill_note_doc', 'external' => 'billing_bill_note_doc',
'self' => 'billing_bill_note_item', 'self' => 'billing_bill_note_bill',
], ],
]; ];

View File

@ -80,7 +80,7 @@ final class PurchaseBillMapper extends BillMapper
public static function getPurchaseByItemId(int $id, \DateTime $start, \DateTime $end) : Money public static function getPurchaseByItemId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_bill_element_total_purchaseprice_net)') $result = $query->select('SUM(billing_bill_element_total_netpurchaseprice)')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -99,7 +99,7 @@ final class PurchaseBillMapper extends BillMapper
public static function getPurchaseBySupplierId(int $id, \DateTime $start, \DateTime $end) : Money public static function getPurchaseBySupplierId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_bill_net)') $result = $query->select('SUM(billing_bill_netcosts)')
->from(self::$table) ->from(self::$table)
->where(self::$table . '.billing_bill_supplier', '=', $id) ->where(self::$table . '.billing_bill_supplier', '=', $id)
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
@ -116,7 +116,7 @@ final class PurchaseBillMapper extends BillMapper
public static function getAvgPurchasePriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money public static function getAvgPurchasePriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_bill_element_single_purchaseprice_net)', 'COUNT(billing_bill_element_total_purchaseprice_net)') $result = $query->select('SUM(billing_bill_element_single_netpurchaseprice)', 'COUNT(billing_bill_element_total_netpurchaseprice)')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -192,7 +192,7 @@ final class PurchaseBillMapper extends BillMapper
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique? // @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query = self::getQuery(null, [], RelationType::ALL, $depth);
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth) $query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill') ->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id) ->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
@ -216,7 +216,7 @@ final class PurchaseBillMapper extends BillMapper
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique? // @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query = self::getQuery(null, [], RelationType::ALL, $depth);
$query->where(self::$table . '_d' . $depth . '.billing_bill_supplier', '=', $id) $query->where(self::$table . '_d' . $depth . '.billing_bill_supplier', '=', $id)
->limit($limit); ->limit($limit);
@ -236,8 +236,8 @@ final class PurchaseBillMapper extends BillMapper
{ {
$depth = 3; $depth = 3;
$query ??= SupplierMapper::getQuery(null, [], RelationType::ALL, $depth); $query = SupplierMapper::getQuery(null, [], RelationType::ALL, $depth);
$query->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_purchase') $query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
->leftJoin(self::$table, self::$table . '_d' . $depth) ->leftJoin(self::$table, self::$table . '_d' . $depth)
->on(SupplierMapper::getTable() . '_d' . $depth . '.suppliermgmt_supplier_id', '=', self::$table . '_d' . $depth . '.billing_bill_supplier') ->on(SupplierMapper::getTable() . '_d' . $depth . '.suppliermgmt_supplier_id', '=', self::$table . '_d' . $depth . '.billing_bill_supplier')
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth) ->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
@ -262,7 +262,7 @@ final class PurchaseBillMapper extends BillMapper
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select(CountryMapper::getTable() . '.country_region') $result = $query->select(CountryMapper::getTable() . '.country_region')
->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_purchase') ->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -285,7 +285,7 @@ final class PurchaseBillMapper extends BillMapper
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select(CountryMapper::getTable() . '.country_code2') $result = $query->select(CountryMapper::getTable() . '.country_code2')
->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_purchase') ->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -309,8 +309,7 @@ final class PurchaseBillMapper extends BillMapper
public static function getItemMonthlyPurchaseCosts(int $id, \DateTime $start, \DateTime $end) : array public static function getItemMonthlyPurchaseCosts(int $id, \DateTime $start, \DateTime $end) : array
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_purchase') $result = $query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_costs')
->selectAs('YEAR(billing_bill_performance_date)', 'year') ->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_bill_performance_date)', 'month') ->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::$table) ->from(self::$table)
@ -333,8 +332,7 @@ final class PurchaseBillMapper extends BillMapper
public static function getSupplierMonthlyPurchaseCosts(int $id, \DateTime $start, \DateTime $end) : array public static function getSupplierMonthlyPurchaseCosts(int $id, \DateTime $start, \DateTime $end) : array
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_bill_net)', 'net_purchase') $result = $query->selectAs('SUM(billing_bill_netcosts)', 'net_purchase')
->selectAs('SUM(billing_bill_costs)', 'net_costs')
->selectAs('YEAR(billing_bill_performance_date)', 'year') ->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_bill_performance_date)', 'month') ->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::$table) ->from(self::$table)

View File

@ -80,7 +80,7 @@ final class SalesBillMapper extends BillMapper
public static function getSalesByItemId(int $id, \DateTime $start, \DateTime $end) : Money public static function getSalesByItemId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_bill_element_total_salesprice_net)') $result = $query->select('SUM(billing_bill_element_total_netsalesprice)')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -99,7 +99,7 @@ final class SalesBillMapper extends BillMapper
public static function getSalesByClientId(int $id, \DateTime $start, \DateTime $end) : Money public static function getSalesByClientId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_bill_net)') $result = $query->select('SUM(billing_bill_netsales)')
->from(self::$table) ->from(self::$table)
->where(self::$table . '.billing_bill_client', '=', $id) ->where(self::$table . '.billing_bill_client', '=', $id)
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
@ -116,7 +116,7 @@ final class SalesBillMapper extends BillMapper
public static function getAvgSalesPriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money public static function getAvgSalesPriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_bill_element_single_salesprice_net)', 'COUNT(billing_bill_element_total_salesprice_net)') $result = $query->select('SUM(billing_bill_element_single_netsalesprice)', 'COUNT(billing_bill_element_total_netsalesprice)')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -192,7 +192,7 @@ final class SalesBillMapper extends BillMapper
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique? // @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query = self::getQuery(null, [], RelationType::ALL, $depth);
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth) $query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill') ->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id) ->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
@ -216,7 +216,7 @@ final class SalesBillMapper extends BillMapper
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique? // @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query = self::getQuery(null, [], RelationType::ALL, $depth);
$query->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $id) $query->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $id)
->limit($limit); ->limit($limit);
@ -236,8 +236,8 @@ final class SalesBillMapper extends BillMapper
{ {
$depth = 3; $depth = 3;
$query ??= ClientMapper::getQuery(null, [], RelationType::ALL, $depth); $query = ClientMapper::getQuery(null, [], RelationType::ALL, $depth);
$query->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales') $query->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
->leftJoin(self::$table, self::$table . '_d' . $depth) ->leftJoin(self::$table, self::$table . '_d' . $depth)
->on(ClientMapper::getTable() . '_d' . $depth . '.clientmgmt_client_id', '=', self::$table . '_d' . $depth . '.billing_bill_client') ->on(ClientMapper::getTable() . '_d' . $depth . '.clientmgmt_client_id', '=', self::$table . '_d' . $depth . '.billing_bill_client')
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth) ->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
@ -264,7 +264,7 @@ final class SalesBillMapper extends BillMapper
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique? // @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query = self::getQuery(null, [], RelationType::ALL, $depth);
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth) $query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill') ->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id) ->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
@ -288,7 +288,7 @@ final class SalesBillMapper extends BillMapper
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique? // @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query ??= BillElementMapper::getQuery(null, [], RelationType::ALL, $depth); $query = BillElementMapper::getQuery(null, [], RelationType::ALL, $depth);
$query->leftJoin(self::$table, self::$table . '_d' . $depth) $query->leftJoin(self::$table, self::$table . '_d' . $depth)
->on(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill', '=', self::$table . '_d' . $depth . '.billing_bill_id') ->on(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill', '=', self::$table . '_d' . $depth . '.billing_bill_id')
->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $client) ->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $client)
@ -310,7 +310,7 @@ final class SalesBillMapper extends BillMapper
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select(CountryMapper::getTable() . '.country_region') $result = $query->select(CountryMapper::getTable() . '.country_region')
->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales') ->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -333,7 +333,7 @@ final class SalesBillMapper extends BillMapper
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select(CountryMapper::getTable() . '.country_code2') $result = $query->select(CountryMapper::getTable() . '.country_code2')
->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales') ->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
@ -357,8 +357,8 @@ final class SalesBillMapper extends BillMapper
public static function getItemMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array public static function getItemMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales') $result = $query->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_costs') ->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_costs')
->selectAs('YEAR(billing_bill_performance_date)', 'year') ->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_bill_performance_date)', 'month') ->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::$table) ->from(self::$table)
@ -381,8 +381,8 @@ final class SalesBillMapper extends BillMapper
public static function getClientMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array public static function getClientMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_bill_net)', 'net_sales') $result = $query->selectAs('SUM(billing_bill_netsales)', 'net_sales')
->selectAs('SUM(billing_bill_costs)', 'net_costs') ->selectAs('SUM(billing_bill_netcosts)', 'net_costs')
->selectAs('YEAR(billing_bill_performance_date)', 'year') ->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_bill_performance_date)', 'month') ->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::$table) ->from(self::$table)

View File

@ -181,8 +181,8 @@ echo $this->getData('nav')->render(); ?>
<td><a href="<?= $url; ?>"><?= $value->billZip; ?></a> <td><a href="<?= $url; ?>"><?= $value->billZip; ?></a>
<td><a href="<?= $url; ?>"><?= $value->billCity; ?></a> <td><a href="<?= $url; ?>"><?= $value->billCity; ?></a>
<td><a href="<?= $url; ?>"><?= $value->billCountry; ?></a> <td><a href="<?= $url; ?>"><?= $value->billCountry; ?></a>
<td><a href="<?= $url; ?>"><?= $value->net->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->netSales->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->profit->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->netProfit->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a> <td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a>
<?php endforeach; ?> <?php endforeach; ?>
<?php if ($count === 0) : ?> <?php if ($count === 0) : ?>

View File

@ -70,10 +70,14 @@ final class BillTest extends \PHPUnit\Framework\TestCase
self::assertEquals('', $this->bill->billZip); self::assertEquals('', $this->bill->billZip);
self::assertEquals('', $this->bill->billCountry); self::assertEquals('', $this->bill->billCountry);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->net); self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->netSales);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->gross); self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->grossSales);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->costs);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->profit); self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->netProfit);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->grossProfit);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->netCosts);
self::assertInstanceOf('\phpOMS\Localization\Money', $this->bill->grossCosts);
self::assertEquals(0, $this->bill->payment); self::assertEquals(0, $this->bill->payment);
self::assertEquals('', $this->bill->paymentText); self::assertEquals('', $this->bill->paymentText);
@ -89,7 +93,7 @@ final class BillTest extends \PHPUnit\Framework\TestCase
*/ */
public function testNumberRendering() : void public function testNumberRendering() : void
{ {
$this->bill->number = '{y}{m}{d}-{id}'; $this->bill->numberFormat = '{y}{m}{d}-{id}';
self::assertEquals(\date('Y') . \date('m') . \date('d') . '-0', $this->bill->getNumber()); self::assertEquals(\date('Y') . \date('m') . \date('d') . '-0', $this->bill->getNumber());
} }
@ -171,6 +175,7 @@ final class BillTest extends \PHPUnit\Framework\TestCase
public function testSerialize() : void public function testSerialize() : void
{ {
$this->bill->number = '123456'; $this->bill->number = '123456';
$this->bill->numberFormat = '{y}';
$this->bill->type = 2; $this->bill->type = 2;
$this->bill->shipTo = 'To'; $this->bill->shipTo = 'To';
$this->bill->shipFAO = 'FAO'; $this->bill->shipFAO = 'FAO';
@ -189,6 +194,7 @@ final class BillTest extends \PHPUnit\Framework\TestCase
[ [
'id' => 0, 'id' => 0,
'number' => '123456', 'number' => '123456',
'numberFormat' => '{y}',
'type' => 2, 'type' => 2,
'shipTo' => 'To', 'shipTo' => 'To',
'shipFAO' => 'FAO', 'shipFAO' => 'FAO',