From 6cd67a528070e075c30a5f35e3ac06134d71301b Mon Sep 17 00:00:00 2001 From: Nadim Salloum Date: Wed, 20 Oct 2021 16:14:00 +0200 Subject: [PATCH] add new paymenttype 'cembra' --- README.md | 2 +- app/Enums/PaymentType.php | 1 + app/Models/Contract.php | 6 ++++ app/Models/Payment.php | 24 ++++++++++++-- public/js/app.js | 26 +++++++++++---- .../js/Components/Payments/CreateModal.vue | 1 + resources/js/Pages/Cars/Edit.vue | 2 +- .../Contracts/Components/ContractForm.vue | 1 + resources/views/contract.blade.php | 32 +++++++++++++------ 9 files changed, 75 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4536e97..69d2c84 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ Steps: 3. Run migrations and seed db: `sail php artisan migrate:fresh --seed` 4. `sail npm run watch` 5. Access the web application at `0.0.0.0` -6. The default credentials are `hello@salloum.ch` and `abc123` +6. The default credentials can be seen/set in the .env \ No newline at end of file diff --git a/app/Enums/PaymentType.php b/app/Enums/PaymentType.php index 18ee060..bd43bfb 100644 --- a/app/Enums/PaymentType.php +++ b/app/Enums/PaymentType.php @@ -12,4 +12,5 @@ final class PaymentType extends Enum { const Transaction = '0'; const Cash = '1'; + const Cembra = '2'; } diff --git a/app/Models/Contract.php b/app/Models/Contract.php index 6eaf6a6..b63dcc0 100644 --- a/app/Models/Contract.php +++ b/app/Models/Contract.php @@ -63,6 +63,12 @@ class Contract extends Model return Money::CHF($this->payments()->transactionOnly()->sum('amount')); } + public function getPaidInCembraAttribute() + { + + return Money::CHF($this->payments()->cembraOnly()->sum('amount')); + } + public function getLeftToPayAttribute() { diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 4dd7003..7dd5759 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -42,12 +42,27 @@ class Payment extends Model public function getTypeAttribute($type) { - return $type == PaymentType::Transaction() ? 'Banküberweisung' : 'Barzahlung'; + + switch ($type) { + case PaymentType::Transaction(): + return 'Banküberweisung'; + case PaymentType::Cash(): + return 'Barzahlung'; + default: + return 'Überweisung via Cembra'; + }; } public function getTypeTextAttribute() { - return $this->type == 'Banküberweisung' ? 'via Banküberweisung erhalten' : 'in bar erhalten'; + switch ($this->type) { + case 'Banküberweisung': + return 'via Banküberweisung erhalten'; + case 'Barzahlung': + return 'in bar erhalten'; + default: + return 'via Cembra-Überweisung erhalten'; + }; } public function getDeleteLinkAttribute() @@ -64,4 +79,9 @@ class Payment extends Model { $query->where('type', PaymentType::Transaction()); } + + public function scopeCembraOnly($query) + { + $query->where('type', PaymentType::Cembra()); + } } diff --git a/public/js/app.js b/public/js/app.js index b9f5ffb..173c286 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -22324,7 +22324,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope colour: this.car.colour, notes: this.car.notes, car_model_id: this.car.car_model.id, - last_check_date: new Date(this.car.last_check_date).toJSON().slice(0, 10).split('-').reverse().join('.'), + last_check_date: this.car.last_check_date ? new Date(this.car.last_check_date).toJSON().slice(0, 10).split('-').reverse().join('.') : '', kilometers: this.car.kilometers, known_damage: this.car.known_damage }, "notes", this.car.notes) @@ -25488,8 +25488,9 @@ var _hoisted_5 = { }; var _hoisted_6 = ["selected"]; var _hoisted_7 = ["selected"]; +var _hoisted_8 = ["selected"]; -var _hoisted_8 = /*#__PURE__*/(0,vue__WEBPACK_IMPORTED_MODULE_0__.createTextVNode)(" Einzahlung speichern "); +var _hoisted_9 = /*#__PURE__*/(0,vue__WEBPACK_IMPORTED_MODULE_0__.createTextVNode)(" Einzahlung speichern "); function render(_ctx, _cache, $props, $setup, $data, $options) { var _component_jet_label = (0,vue__WEBPACK_IMPORTED_MODULE_0__.resolveComponent)("jet-label"); @@ -25574,7 +25575,12 @@ function render(_ctx, _cache, $props, $setup, $data, $options) { selected: $data.form.type == '1' }, "Barzahlung", 8 /* PROPS */ - , _hoisted_7)], 512 + , _hoisted_7), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("option", { + value: "2", + selected: $data.form.type == '2' + }, "Cembra-Überweisung", 8 + /* PROPS */ + , _hoisted_8)], 512 /* NEED_PATCH */ ), [[vue__WEBPACK_IMPORTED_MODULE_0__.vModelSelect, $data.form.type]]), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createVNode)(_component_jet_input_error, { message: $data.form.errors.type, @@ -25594,7 +25600,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) { disabled: $data.form.processing }, { "default": (0,vue__WEBPACK_IMPORTED_MODULE_0__.withCtx)(function () { - return [_hoisted_8]; + return [_hoisted_9]; }), _: 1 /* STABLE */ @@ -31162,7 +31168,8 @@ var _hoisted_8 = { }; var _hoisted_9 = ["selected"]; var _hoisted_10 = ["selected"]; -var _hoisted_11 = { +var _hoisted_11 = ["selected"]; +var _hoisted_12 = { "class": "col-span-6" }; function render(_ctx, _cache, $props, $setup, $data, $options) { @@ -31311,14 +31318,19 @@ function render(_ctx, _cache, $props, $setup, $data, $options) { selected: $data.form.payment_type == '1' }, "Barzahlung", 8 /* PROPS */ - , _hoisted_10)], 512 + , _hoisted_10), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("option", { + value: "2", + selected: $data.form.payment_type == '2' + }, "Cembra-Überweisung", 8 + /* PROPS */ + , _hoisted_11)], 512 /* NEED_PATCH */ ), [[vue__WEBPACK_IMPORTED_MODULE_0__.vModelSelect, $data.form.payment_type]]), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createVNode)(_component_jet_input_error, { message: $data.form.errors.type, "class": "mt-2" }, null, 8 /* PROPS */ - , ["message"])])) : (0,vue__WEBPACK_IMPORTED_MODULE_0__.createCommentVNode)("v-if", true), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("div", _hoisted_11, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createVNode)(_component_jet_label, { + , ["message"])])) : (0,vue__WEBPACK_IMPORTED_MODULE_0__.createCommentVNode)("v-if", true), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("div", _hoisted_12, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createVNode)(_component_jet_label, { "for": "notes", value: "Bemerkungen" }), (0,vue__WEBPACK_IMPORTED_MODULE_0__.withDirectives)((0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("textarea", { diff --git a/resources/js/Components/Payments/CreateModal.vue b/resources/js/Components/Payments/CreateModal.vue index 72f3e5b..07716d8 100644 --- a/resources/js/Components/Payments/CreateModal.vue +++ b/resources/js/Components/Payments/CreateModal.vue @@ -23,6 +23,7 @@ diff --git a/resources/js/Pages/Cars/Edit.vue b/resources/js/Pages/Cars/Edit.vue index 07d158b..3fa59fc 100644 --- a/resources/js/Pages/Cars/Edit.vue +++ b/resources/js/Pages/Cars/Edit.vue @@ -65,7 +65,7 @@ export default { colour: this.car.colour, notes: this.car.notes, car_model_id: this.car.car_model.id, - last_check_date: new Date(this.car.last_check_date).toJSON().slice(0,10).split('-').reverse().join('.'), + last_check_date: this.car.last_check_date ? new Date(this.car.last_check_date).toJSON().slice(0,10).split('-').reverse().join('.') : '', kilometers: this.car.kilometers, known_damage: this.car.known_damage, notes: this.car.notes, diff --git a/resources/js/Pages/Contracts/Components/ContractForm.vue b/resources/js/Pages/Contracts/Components/ContractForm.vue index d4021a7..6fe0bbf 100644 --- a/resources/js/Pages/Contracts/Components/ContractForm.vue +++ b/resources/js/Pages/Contracts/Components/ContractForm.vue @@ -46,6 +46,7 @@ diff --git a/resources/views/contract.blade.php b/resources/views/contract.blade.php index a540fb8..d4b24a5 100644 --- a/resources/views/contract.blade.php +++ b/resources/views/contract.blade.php @@ -153,21 +153,35 @@ MwSt-Nr: CHE-226.272.050 {{ $contract->insurance_type_formatted }}   + + - - + + - @if ($contract->paid_in_cash->getAmount() && $contract->paid_in_transaction->getAmount()) - - @elseif ($contract->paid_in_cash->getAmount()) - - @elseif ($contract->paid_in_transaction->getAmount()) - + + {{ $contract->paid }} @endif +
Kaufpreis{{ $contract->price }}Kaufpreis{{ $contract->price }}
Anzahlung{{ $contract->paid_in_cash }} in bar
{{ $contract->paid_in_transaction }} via Überweisung
{{ $contract->paid_in_cash }} in bar{{ $contract->paid_in_transaction }} via Überweisung + @if ($contract->paid_in_cash->getAmount() || $contract->paid_in_transaction->getAmount() || $contract->paid_in_cembra->getAmount()) + @if ($contract->paid_in_cash->getAmount()) + {{ $contract->paid_in_cash }} in bar + @if ($contract->paid_in_transaction->getAmount() || $contract->paid_in_cembra->getAmount()) +
+ @endif + @endif + @if ($contract->paid_in_transaction->getAmount()) + {{ $contract->paid_in_transaction }} via Überweisung + @if ($contract->paid_in_cembra->getAmount()) +
+ @endif + @endif + @if ($contract->paid_in_cembra->getAmount()) + {{ $contract->paid_in_cembra }} via Cembra-Überweisung + @endif @else -
{{ $contract->paid }}
Restbetrag