}
if ($exportImportTable) {
- $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
- ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
- ->where(['between', 'wo.date', $weekStart, $weekEnd])
- ->andWhere(['wo.store_id' => $exportImportTable->export_val])
- ->asArray()->all();
+ $writeOffs = self::getWriteOffs($exportImportTable->export_val, $weekStart, $weekEnd);
$selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid', 'date'])
->where(['between', 'date', $weekStart, $weekEnd])
if ($key == WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK) {
if ($store_id == 4 /* Аэродромная */ ) {
- $writeOffsResult = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
- ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
- ->where(['between', 'wo.date', $weekStart, $weekEnd])
- ->asArray()->all();
+ $writeOffsResult = self::getWriteOffsAllStores($weekStart, $weekEnd);
} else {
$writeOffsResult = [];
}
return $writeOffs;
}
+ private static function getWriteOffsAllStores($periodStart, $periodEnd) {
+ $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
+ ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
+ ->where(['between', 'wo.date', $periodStart, $periodEnd])
+ ->asArray()->all();
+
+ return $writeOffs;
+ }
+
public static function calculateMonthDefect($year, $month) {
$monthStart = date("Y-m-d 00:00:00", strtotime($year . '-' . $month . '-1'));
$monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1'));
foreach (MotivationCostsItem::writeOffsToMotivationItemArray() as $key => $motivationItemType) {
if ($key == WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK) {
if ($store_id == 4 /* Аэродромная */) {
- $writeOffsResult = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
- ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
- ->where(['between', 'wo.date', $monthStart, $monthEnd])
- ->asArray()->all();
+ $writeOffsResult = self::getWriteOffsAllStores($monthStart, $monthEnd);
} else {
$writeOffsResult = [];
}