Skip to content
Code-Schnipsel Gruppen Projekte
Commit 952a3337 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: #54 - invoice delivery address

Übergeordneter 485bea9e
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
* This file contains package_quiqqer_invoice_ajax_invoices_temporary_save * This file contains package_quiqqer_invoice_ajax_invoices_temporary_save
*/ */
use QUI\ERP\Shipping\Shipping;
use QUI\ERP\Accounting\Invoice\Handler as InvoiceHandler;
/** /**
* Saves the temporary invoice * Saves the temporary invoice
* *
...@@ -13,7 +16,7 @@ ...@@ -13,7 +16,7 @@
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_invoice_ajax_invoices_temporary_save', 'package_quiqqer_invoice_ajax_invoices_temporary_save',
function ($invoiceId, $data) { function ($invoiceId, $data) {
$Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance(); $Invoices = InvoiceHandler::getInstance();
$Invoice = $Invoices->getTemporaryInvoice($invoiceId); $Invoice = $Invoices->getTemporaryInvoice($invoiceId);
$data = \json_decode($data, true); $data = \json_decode($data, true);
...@@ -22,6 +25,20 @@ function ($invoiceId, $data) { ...@@ -22,6 +25,20 @@ function ($invoiceId, $data) {
$data['invoice_address'] = ''; $data['invoice_address'] = '';
} }
if (isset($data['addressDelivery']) && !empty($data['addressDelivery'])) {
$delivery = $data['addressDelivery'];
if ($delivery) {
unset($data['addressDelivery']);
try {
$Invoice->setDeliveryAddress($delivery);
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
}
$Invoice->clearArticles(); $Invoice->clearArticles();
if (isset($data['articles'])) { if (isset($data['articles'])) {
......
...@@ -225,6 +225,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/DeliveryAddress', [ ...@@ -225,6 +225,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/DeliveryAddress', [
return this.getUser().then(function (User) { return this.getUser().then(function (User) {
return User.getAddressList(); return User.getAddressList();
}).then(function (addresses) { }).then(function (addresses) {
self.$Addresses.set('html', '');
new Element('option', { new Element('option', {
value : '', value : '',
html : '', html : '',
......
...@@ -60,6 +60,68 @@ ...@@ -60,6 +60,68 @@
</tbody> </tbody>
</table> </table>
<table class="data-table data-table-flexbox invoice-delivery-data" style="display: none">
<thead>
<tr>
<th>{{textInvoiceDelivery}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label class="field-container">
<span class="field-container-item" title="{{textCustomer}}">
{{textCustomer}}
</span>
<input type="text" class="field-container-field" name="delivery-customer" disabled/>
</label>
</td>
</tr>
<tr>
<td>
<label class="field-container">
<span class="field-container-item" title="{{textCompany}}">
{{textDeliveryCompany}}
</span>
<input type="text" class="field-container-field" name="delivery-company" disabled/>
</label>
</td>
</tr>
<tr>
<td>
<label class="field-container">
<span class="field-container-item" title="{{textStreet}}">
{{textDeliveryStreet}}
</span>
<input type="text" class="field-container-field" name="delivery-street_no" disabled/>
</label>
</td>
</tr>
<tr>
<td>
<label class="field-container">
<span class="field-container-item" title="{{textZip}}">
{{textDeliveryZip}}
</span>
<input type="text" class="field-container-field" name="delivery-zip" disabled/>
</label>
</td>
</tr>
<tr>
<td>
<label class="field-container">
<span class="field-container-item" title="{{textCity}}">
{{textDeliveryCity}}
</span>
<input type="text" class="field-container-field" name="delivery-city" disabled/>
</label>
</td>
</tr>
</tbody>
</table>
<table class="data-table data-table-flexbox invoice-data"> <table class="data-table data-table-flexbox invoice-data">
<thead> <thead>
<tr> <tr>
...@@ -187,4 +249,4 @@ ...@@ -187,4 +249,4 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
\ No newline at end of file
...@@ -504,6 +504,13 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [ ...@@ -504,6 +504,13 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [
data.textZip = QUILocale.get(lg, 'zip'); data.textZip = QUILocale.get(lg, 'zip');
data.textCity = QUILocale.get(lg, 'city'); data.textCity = QUILocale.get(lg, 'city');
data.textInvoiceDelivery = QUILocale.get(lg, 'deliveryAddress');
data.textDeliveryCompany = QUILocale.get(lg, 'company');
data.textDeliveryStreet = QUILocale.get(lg, 'street');
data.textDeliveryZip = QUILocale.get(lg, 'zip');
data.textDeliveryCity = QUILocale.get(lg, 'city');
data.textDeliveryCountry = QUILocale.get(lg, 'country');
data.textInvoiceData = QUILocale.get(lg, 'erp.panel.invoice.data.title'); data.textInvoiceData = QUILocale.get(lg, 'erp.panel.invoice.data.title');
data.textInvoiceDate = QUILocale.get(lg, 'erp.panel.invoice.data.date'); data.textInvoiceDate = QUILocale.get(lg, 'erp.panel.invoice.data.date');
data.textProjectName = QUILocale.get(lg, 'erp.panel.invoice.data.projectName'); data.textProjectName = QUILocale.get(lg, 'erp.panel.invoice.data.projectName');
...@@ -520,9 +527,11 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [ ...@@ -520,9 +527,11 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [
html: Mustache.render(template, data) html: Mustache.render(template, data)
}); });
var Form = Container.getElement('form');
var address = {};
try { try {
var Form = Container.getElement('form'), address = JSON.decode(data.invoice_address);
address = JSON.decode(data.invoice_address);
Form.elements.customer.value = address.salutation + ' ' + address.firstname + ' ' + address.lastname; Form.elements.customer.value = address.salutation + ' ' + address.firstname + ' ' + address.lastname;
Form.elements.company.value = address.company; Form.elements.company.value = address.company;
...@@ -533,6 +542,40 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [ ...@@ -533,6 +542,40 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/Invoice', [
console.error(e); console.error(e);
} }
if (data.delivery_address !== '') {
Container.getElement('.invoice-delivery-data').setStyle('display', null);
try {
var deliveryAddress = JSON.decode(data.delivery_address);
if (typeof deliveryAddress.salutation === 'undefined') {
deliveryAddress.salutation = '';
}
if (typeof deliveryAddress.firstname === 'undefined') {
deliveryAddress.firstname = address.firstname;
}
if (typeof deliveryAddress.lastname === 'undefined') {
deliveryAddress.lastname = address.lastname;
}
Form.elements['delivery-customer'].value = deliveryAddress.salutation + ' ' +
deliveryAddress.firstname + ' ' +
deliveryAddress.lastname;
Form.elements['delivery-company'].value = deliveryAddress.company;
Form.elements['delivery-street_no'].value = deliveryAddress.street_no;
Form.elements['delivery-zip'].value = deliveryAddress.zip;
Form.elements['delivery-city'].value = deliveryAddress.city;
} catch (e) {
console.error(e);
}
}
console.log(data);
resolve(); resolve();
}); });
}); });
......
...@@ -88,6 +88,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ...@@ -88,6 +88,7 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [
this.$ArticleListSummary = null; this.$ArticleListSummary = null;
this.$AddProduct = null; this.$AddProduct = null;
this.$ArticleSort = null; this.$ArticleSort = null;
this.$AddressDelivery = null;
this.$AddSeparator = null; this.$AddSeparator = null;
this.$SortSeparator = null; this.$SortSeparator = null;
...@@ -254,7 +255,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ...@@ -254,7 +255,8 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [
ordered_by : this.getAttribute('ordered_by'), ordered_by : this.getAttribute('ordered_by'),
time_for_payment : this.getAttribute('time_for_payment'), time_for_payment : this.getAttribute('time_for_payment'),
payment_method : this.getAttribute('payment_method'), payment_method : this.getAttribute('payment_method'),
additional_invoice_text: this.getAttribute('additional_invoice_text') additional_invoice_text: this.getAttribute('additional_invoice_text'),
addressDelivery : this.getAttribute('addressDelivery')
}; };
}, },
...@@ -446,10 +448,20 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ...@@ -446,10 +448,20 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [
).get('data-quiid') ).get('data-quiid')
); );
console.log(self.getAttribute('addressDelivery')); if (self.getAttribute('delivery_address')) {
var deliveryAddress = self.getAttribute('delivery_address');
if (self.getAttribute('addressDelivery') && self.getAttribute('hasDeliveryAddress')) { try {
self.$AddressDelivery.setValue(self.getAttribute('addressDelivery')); deliveryAddress = JSON.decode(deliveryAddress);
if (deliveryAddress) {
self.getContent().getElement('[name="differentDeliveryAddress"]').checked = true;
self.$AddressDelivery.setAttribute('userId', self.getAttribute('customer_id'));
self.$AddressDelivery.setValue(deliveryAddress);
}
} catch (e) {
}
} }
}).then(function () { }).then(function () {
var Container = self.getContent().getElement('.container'); var Container = self.getContent().getElement('.container');
...@@ -464,7 +476,9 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ...@@ -464,7 +476,9 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [
}, },
events : { events : {
onClick: function () { onClick: function () {
self.openArticles(); self.openArticles().catch(function (e) {
console.error(e);
});
} }
} }
}).inject(Container); }).inject(Container);
...@@ -935,6 +949,11 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ...@@ -935,6 +949,11 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [
callback: function () { callback: function () {
self.$unloadCategory(); self.$unloadCategory();
if (self.$AddressDelivery) {
self.$AddressDelivery.destroy();
self.$AddressDelivery = null;
}
Container.set('html', ''); Container.set('html', '');
Container.setStyle('padding', 20); Container.setStyle('padding', 20);
...@@ -994,6 +1013,10 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [ ...@@ -994,6 +1013,10 @@ define('package/quiqqer/invoice/bin/backend/controls/panels/TemporaryInvoice', [
} }
} }
if (this.$AddressDelivery) {
this.setAttribute('addressDelivery', this.$AddressDelivery.getValue());
}
if (this.$AdditionalText) { if (this.$AdditionalText) {
this.setAttribute( this.setAttribute(
'additional_invoice_text', 'additional_invoice_text',
......
...@@ -83,6 +83,11 @@ class InvoiceTemporary extends QUI\QDOM ...@@ -83,6 +83,11 @@ class InvoiceTemporary extends QUI\QDOM
*/ */
protected $shippingId = null; protected $shippingId = null;
/**
* @var array
*/
protected $addressDelivery = [];
/** /**
* Invoice constructor. * Invoice constructor.
* *
...@@ -104,6 +109,12 @@ public function __construct($id, Handler $Handler) ...@@ -104,6 +109,12 @@ public function __construct($id, Handler $Handler)
$this->History = new QUI\ERP\Comments(); $this->History = new QUI\ERP\Comments();
$this->Comments = new QUI\ERP\Comments(); $this->Comments = new QUI\ERP\Comments();
$this->addressDelivery = \json_decode($data['delivery_address'], true);
if (!empty($data['delivery_address_id'])) {
$this->addressDelivery['id'] = (int)$data['delivery_address_id'];
}
if (isset($data['articles'])) { if (isset($data['articles'])) {
$articles = \json_decode($data['articles'], true); $articles = \json_decode($data['articles'], true);
...@@ -173,7 +184,6 @@ public function __construct($id, Handler $Handler) ...@@ -173,7 +184,6 @@ public function __construct($id, Handler $Handler)
$this->setAttributes($data); $this->setAttributes($data);
if (!$this->getCustomer()) { if (!$this->getCustomer()) {
$this->setAttribute('invoice_address', false); $this->setAttribute('invoice_address', false);
$this->setAttribute('customer_id', false); $this->setAttribute('customer_id', false);
...@@ -703,6 +713,20 @@ public function update($PermissionUser = null) ...@@ -703,6 +713,20 @@ public function update($PermissionUser = null)
$shippingData = $this->getShipping()->toJSON(); $shippingData = $this->getShipping()->toJSON();
} }
// delivery address
$deliveryAddress = '';
$deliveryAddressId = null;
if ($this->getDeliveryAddress()) {
$deliveryAddress = $this->getDeliveryAddress()->toJSON();
$deliveryAddressId = $this->getDeliveryAddress()->getId();
if (empty($deliveryAddressId)) {
$deliveryAddressId = null;
}
}
QUI::getEvents()->fireEvent( QUI::getEvents()->fireEvent(
'quiqqerInvoiceTemporaryInvoiceSave', 'quiqqerInvoiceTemporaryInvoiceSave',
[$this] [$this]
...@@ -729,8 +753,8 @@ public function update($PermissionUser = null) ...@@ -729,8 +753,8 @@ public function update($PermissionUser = null)
// address // address
'invoice_address_id' => (int)$this->getAttribute('invoice_address_id'), 'invoice_address_id' => (int)$this->getAttribute('invoice_address_id'),
'invoice_address' => $invoiceAddress, 'invoice_address' => $invoiceAddress,
'delivery_address_id' => null, 'delivery_address_id' => $deliveryAddressId,
'delivery_address' => null, 'delivery_address' => $deliveryAddress,
// processing // processing
'time_for_payment' => $timeForPayment, 'time_for_payment' => $timeForPayment,
...@@ -1029,6 +1053,17 @@ public function post($PermissionUser = null) ...@@ -1029,6 +1053,17 @@ public function post($PermissionUser = null)
$shippingData = $this->getShipping()->toJSON(); $shippingData = $this->getShipping()->toJSON();
} }
// delivery address
$deliveryAddress = $this->getAttribute('delivery_address');
if (empty($deliveryAddress)) {
$DeliveryAddress = $this->getDeliveryAddress();
if ($DeliveryAddress) {
$deliveryAddress = $DeliveryAddress->toJSON();
}
}
// create invoice // create invoice
QUI::getDataBase()->insert( QUI::getDataBase()->insert(
$Handler->invoiceTable(), $Handler->invoiceTable(),
...@@ -1050,7 +1085,7 @@ public function post($PermissionUser = null) ...@@ -1050,7 +1085,7 @@ public function post($PermissionUser = null)
// addresses // addresses
'invoice_address' => $invoiceAddress, 'invoice_address' => $invoiceAddress,
'delivery_address' => $this->getAttribute('delivery_address'), 'delivery_address' => $deliveryAddress,
// payments // payments
'payment_method' => $this->getAttribute('payment_method'), 'payment_method' => $this->getAttribute('payment_method'),
...@@ -1665,4 +1700,94 @@ public function setShipping(QUI\ERP\Shipping\Api\ShippingInterface $Shipping) ...@@ -1665,4 +1700,94 @@ public function setShipping(QUI\ERP\Shipping\Api\ShippingInterface $Shipping)
} }
//endregion //endregion
//region delivery address
/**
* Return delivery address
*
* @return QUI\ERP\Address|null
*/
public function getDeliveryAddress()
{
$delivery = $this->addressDelivery;
if (isset($delivery['id'])) {
unset($delivery['id']);
}
if (empty($delivery)) {
try {
$Customer = QUI::getUsers()->get((int)$this->getAttribute('customer_id'));
$Address = $Customer->getAddress(
(int)$this->getAttribute('invoice_address_id')
);
if ($Address) {
return new QUI\ERP\Address(
$Address->getAttributes(),
$this->getCustomer()
);
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::addDebug($Exception->getMessage());
}
}
if (empty($this->addressDelivery)) {
return null;
}
return new QUI\ERP\Address($this->addressDelivery, $this->getCustomer());
}
/**
* Set the delivery address
*
* @param array|QUI\ERP\Address $address
*/
public function setDeliveryAddress($address)
{
if ($address instanceof QUI\ERP\Address) {
$this->addressDelivery = $address->getAttributes();
return;
}
if (\is_array($address)) {
$this->addressDelivery = $this->parseAddressData($address);
}
}
/**
* @param array $address
* @return array
*/
protected function parseAddressData(array $address)
{
$fields = \array_flip([
'id',
'salutation',
'firstname',
'lastname',
'street_no',
'zip',
'city',
'country',
'company'
]);
$result = [];
foreach ($address as $entry => $value) {
if (isset($fields[$entry])) {
$result[$entry] = $value;
}
}
return $result;
}
// endregion
} }
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren