1
|
|
|
<?php |
2
|
|
|
namespace Hideyo\Ecommerce\Framework\Repositories; |
3
|
|
|
|
4
|
|
|
use Hideyo\Ecommerce\Framework\Models\Invoice; |
5
|
|
|
use Hideyo\Ecommerce\Framework\Models\InvoiceRule; |
6
|
|
|
use Hideyo\Ecommerce\Framework\Models\InvoiceAddress; |
7
|
|
|
use Hideyo\Ecommerce\Framework\Models\InvoiceSendingMethod; |
|
|
|
|
8
|
|
|
use Hideyo\Ecommerce\Framework\Models\InvoicePaymentMethod; |
|
|
|
|
9
|
|
|
use Hideyo\Ecommerce\Framework\Repositories\OrderRepository; |
|
|
|
|
10
|
|
|
use Hideyo\Ecommerce\Framework\Repositories\ClientRepository; |
|
|
|
|
11
|
|
|
use Hideyo\Ecommerce\Framework\Repositories\InvoiceAddressRepository; |
12
|
|
|
use Hideyo\Ecommerce\Framework\Repositories\SendingMethodRepository; |
|
|
|
|
13
|
|
|
use Hideyo\Ecommerce\Framework\Repositories\PaymentMethodRepository; |
|
|
|
|
14
|
|
|
use Validator; |
15
|
|
|
|
16
|
|
|
class InvoiceRepository extends BaseRepository |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
protected $model; |
20
|
|
|
|
21
|
|
|
public function __construct( |
22
|
|
|
Invoice $model, |
23
|
|
|
OrderRepository $order, |
24
|
|
|
ClientRepository $client, |
25
|
|
|
InvoiceAddressRepository $invoiceAddress, |
26
|
|
|
SendingMethodRepository $sendingMethod, |
27
|
|
|
PaymentMethodRepository $paymentMethod |
28
|
|
|
) { |
29
|
|
|
$this->model = $model; |
30
|
|
|
$this->client = $client; |
|
|
|
|
31
|
|
|
$this->order = $order; |
|
|
|
|
32
|
|
|
$this->invoiceAddress = $invoiceAddress; |
|
|
|
|
33
|
|
|
$this->paymentMethod = $paymentMethod; |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->sendingMethod = $sendingMethod; |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The validation rules for the model. |
40
|
|
|
* |
41
|
|
|
* @param integer $id id attribute model |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
private function rules($id = false) |
45
|
|
|
{ |
46
|
|
|
$rules = array( |
47
|
|
|
'order_id' => 'required|unique:invoice', |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $rules; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function create(array $attributes) |
55
|
|
|
{ |
56
|
|
|
$attributes['shop_id'] = auth()->user()->selected_shop_id; |
57
|
|
|
$attributes['modified_by_user_id'] = auth()->user()->id; |
58
|
|
|
$this->model->fill($attributes); |
59
|
|
|
$this->model->save(); |
60
|
|
|
|
61
|
|
|
if (isset($attributes['categories'])) { |
62
|
|
|
$this->model->categories()->sync($attributes['categories']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $this->model; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function generateInvoiceFromOrder($orderId) |
69
|
|
|
{ |
70
|
|
|
$order = $this->order->find($orderId); |
71
|
|
|
|
72
|
|
|
if ($order->count()) { |
73
|
|
|
$attributes = $order->toArray(); |
74
|
|
|
$attributes['order_id'] = $order->id; |
75
|
|
|
|
76
|
|
|
$validator = Validator::make($attributes, $this->rules()); |
77
|
|
|
|
78
|
|
|
if ($validator->fails()) { |
79
|
|
|
return $validator; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->model->fill($attributes); |
83
|
|
|
$this->model->save(); |
84
|
|
|
|
85
|
|
|
if ($this->model->id) { |
86
|
|
|
if ($order->products) { |
87
|
|
|
foreach ($order->products as $product) { |
88
|
|
|
$product = $product->toArray(); |
89
|
|
|
$product['product_id'] = $product['product_id']; |
90
|
|
|
|
91
|
|
|
if (isset($product['product_combination_id'])) { |
92
|
|
|
$product['product_attribute_id'] = $product['product_combination_id']; |
93
|
|
|
$productCombinationTitleArray = array(); |
|
|
|
|
94
|
|
|
if (isset($product['product_combination_title']) and is_array($product['product_combination_title'])) { |
95
|
|
|
foreach ($product['product_combination_title'] as $key => $val) { |
96
|
|
|
$productCombinationTitle[] = $key.': '.$val; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$product['product_attribute_title'] = implode(', ', $productCombinationTitle); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$products[] = new InvoiceRule($product); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if ($order->orderSendingMethod) { |
107
|
|
|
$invoiceRule = array( |
108
|
|
|
'type' => 'sending_cost', |
109
|
|
|
'title' => $order->orderSendingMethod->title, |
110
|
|
|
'tax_rate_id' => $order->orderSendingMethod->tax_rate_id, |
111
|
|
|
'tax_rate' => $order->orderSendingMethod->tax_rate, |
112
|
|
|
'amount' => 1, |
113
|
|
|
'price_with_tax' => $order->orderSendingMethod->price_with_tax, |
114
|
|
|
'price_without_tax' => $order->orderSendingMethod->price_without_tax, |
115
|
|
|
'total_price_with_tax' => $order->orderSendingMethod->price_with_tax, |
116
|
|
|
'total_price_without_tax' => $order->orderSendingMethod->price_without_tax, |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$products[] = new InvoiceRule($invoiceRule); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ($order->orderPaymentMethod) { |
123
|
|
|
$invoiceRule = array( |
124
|
|
|
'type' => 'payment_cost', |
125
|
|
|
'title' => $order->orderPaymentMethod->title, |
126
|
|
|
'tax_rate_id' => $order->orderPaymentMethod->tax_rate_id, |
127
|
|
|
'tax_rate' => $order->orderPaymentMethod->tax_rate, |
128
|
|
|
'amount' => 1, |
129
|
|
|
'price_with_tax' => $order->orderPaymentMethod->price_with_tax, |
130
|
|
|
'price_without_tax' => $order->orderPaymentMethod->price_without_tax, |
131
|
|
|
'total_price_with_tax' => $order->orderPaymentMethod->price_with_tax, |
132
|
|
|
'total_price_without_tax' => $order->orderPaymentMethod->price_without_tax, |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$products[] = new InvoiceRule($invoiceRule); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$this->model->products()->saveMany($products); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if ($order->orderBillAddress and $order->orderDeliveryAddress) { |
142
|
|
|
$deliveryInvoiceAddress = new InvoiceAddress($order->orderBillAddress->toArray()); |
143
|
|
|
|
144
|
|
|
$billInvoiceAddress = new InvoiceAddress($order->orderDeliveryAddress->toArray()); |
145
|
|
|
|
146
|
|
|
$this->model->invoiceAddress()->saveMany(array($deliveryInvoiceAddress, $billInvoiceAddress)); |
147
|
|
|
|
148
|
|
|
$this->model->fill(array('delivery_invoice_address_id' => $deliveryInvoiceAddress->id, 'bill_invoice_address_id' => $billInvoiceAddress->id)); |
149
|
|
|
$this->model->save(); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $this->model; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function updateById(array $attributes, $id) |
158
|
|
|
{ |
159
|
|
|
$this->model = $this->find($id); |
160
|
|
|
$attributes['shop_id'] = auth()->user()->selected_shop_id; |
161
|
|
|
$attributes['modified_by_user_id'] = auth()->user()->id; |
162
|
|
|
return $this->updateEntity($attributes); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function selectAllByAllProductsAndProductCategoryId($productCategoryId) |
166
|
|
|
{ |
167
|
|
|
return $this->model->select('extra_field.*')->leftJoin('product_category_related_extra_field', 'extra_field.id', '=', 'product_category_related_extra_field.extra_field_id')->where('all_products', '=', 1)->orWhere('product_category_related_extra_field.product_category_id', '=', $productCategoryId)->get(); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths