[WIP] Working on orders & invoices
This commit is contained in:
@@ -2,50 +2,55 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Shop\Invoice;
|
||||
|
||||
class Invoices
|
||||
{
|
||||
public static function getOptions()
|
||||
|
||||
public static function saveInvoice($order_id, $data)
|
||||
{
|
||||
return Invoice::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
$data['order_id'] = $order_id;
|
||||
dump($data);
|
||||
exit;
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return Invoice::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Invoice::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Invoice::find($id);
|
||||
return $relations ? Invoice::with($relations)->findOrFail($id) : Invoice::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
$data['ref'] = self::getNewRef();
|
||||
return Invoice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Invoice::destroy($id);
|
||||
}
|
||||
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym') . '00000';
|
||||
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref + 1 : $ref + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user