Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 46 |
| RejectedExport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
132.00 | |
0.00% |
0 / 46 |
| setIds | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| setRejectedBills | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| collection | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 5 |
|||
| getByIds | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| getByRejectedBills | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 6 |
|||
| prependFields | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| injectRecord | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| columnFormats | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 9 |
|||
| <?php | |
| namespace App\Exports; | |
| use App\RejectedBill; | |
| use App\RejectedBillItem; | |
| use Illuminate\Database\Eloquent\Builder; | |
| use Illuminate\Database\Eloquent\Collection; | |
| use Maatwebsite\Excel\Concerns\FromCollection; | |
| use Maatwebsite\Excel\Concerns\ShouldAutoSize; | |
| use Maatwebsite\Excel\Concerns\WithColumnFormatting; | |
| use Maatwebsite\Excel\Concerns\WithCustomValueBinder; | |
| use PhpOffice\PhpSpreadsheet\Style\NumberFormat; | |
| class RejectedExport extends \PhpOffice\PhpSpreadsheet\Cell\StringValueBinder implements FromCollection,ShouldAutoSize,WithColumnFormatting | |
| ,WithCustomValueBinder | |
| { | |
| protected $ids; | |
| static public $max=10000; | |
| protected $rejectedBills; | |
| public function setIds(Array $ids) | |
| { | |
| $this->ids=$ids; | |
| } | |
| public function setRejectedBills($rejectedBills) | |
| { | |
| $this->rejectedBills=$rejectedBills; | |
| } | |
| public function collection() | |
| { | |
| if($this->ids){ | |
| return $this->getByIds(); | |
| } | |
| if($this->rejectedBills){ | |
| return $this->getByRejectedBills(); | |
| } | |
| return null; | |
| } | |
| private function getByIds(){ | |
| $rejectedItems=RejectedBillItem::whereHas('rejectedBill',function(Builder $query){ | |
| $query->whereIn('id',$this->ids); | |
| if(count($this->ids)>self::$max){ | |
| $query->where('is_finished',false); | |
| } | |
| }); | |
| $rejectedItems->get(); | |
| $rejecteds = new Collection(); | |
| $this->prependFields($rejecteds); | |
| $rejectedItems->each(function(RejectedBillItem $item)use($rejecteds){ | |
| $this->injectRecord($rejecteds,$item->rejectedBill,$item); | |
| }); | |
| return $rejecteds; | |
| } | |
| private function getByRejectedBills(){ | |
| $rejecteds = new Collection(); | |
| $this->prependFields($rejecteds); | |
| $this->rejectedBills->each(function(RejectedBill $rejectedBill)use($rejecteds){ | |
| $rejectedBill->items()->each(function (RejectedBillItem $item)use($rejecteds,$rejectedBill){ | |
| $this->injectRecord($rejecteds,$rejectedBill,$item); | |
| }); | |
| }); | |
| return $rejecteds; | |
| } | |
| private function prependFields($collection){ | |
| $collection->prepend(['日期','审核号','客户名称','订单号','姓名', | |
| '手机','原单单号','退回单号','退回公司','到付费用', | |
| '是否入库','商品条码','商品名称','数量','是否正品', | |
| '批次号','生产日期','效期','备注']); | |
| return $collection; | |
| } | |
| private function injectRecord($collection,$bill,$item){ | |
| $collection->push([ | |
| $item['created_at'], | |
| $bill['checked_numbers'],$bill['owner_name'], | |
| $bill['order_number'],$bill['sender'], | |
| $bill['mobile_sender'],$bill['logistic_number'], | |
| $bill['logistic_number_return'],$bill['logistic_name'], | |
| $bill['fee_collected'],$bill['is_loaded_str'], | |
| $item['barcode_goods'],$item['name_goods'],$item['amount'],$item['quality_label'], | |
| $item['batch_number'],$item['made_at'],$item['validity_at'],$item['remark']]); | |
| return $collection; | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function columnFormats(): array | |
| { | |
| return [ | |
| 'B' => NumberFormat::FORMAT_TEXT, | |
| 'C' => NumberFormat::FORMAT_TEXT, | |
| 'D' => NumberFormat::FORMAT_TEXT, | |
| 'E' => NumberFormat::FORMAT_TEXT, | |
| 'F' => NumberFormat::FORMAT_TEXT, | |
| 'G' => NumberFormat::FORMAT_TEXT, | |
| 'H' => NumberFormat::FORMAT_TEXT, | |
| 'L' => NumberFormat::FORMAT_TEXT, | |
| 'N' => NumberFormat::FORMAT_TEXT, | |
| ]; | |
| } | |
| } |