first attempt to record client
This commit is contained in:
parent
cada22694d
commit
013c990540
@ -56,7 +56,8 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button class="btn btn-primary btn-block" id="validate_selling" ng-click="sendForm()">
|
||||
<button class="btn btn-primary btn-block" id="validate_selling" ng-click="sendForm()"
|
||||
ng-disabled="!paidAmount">
|
||||
<i class="fa fa-check"></i>
|
||||
Valider
|
||||
</button>
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\ProductSold;
|
||||
use AppBundle\Entity\SellRecord;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@ -120,20 +122,60 @@ class DefaultController extends Controller {
|
||||
public function addSellingAction( Request $request ) {
|
||||
// var_dump( $request->request );
|
||||
// die();
|
||||
$json = json_decode( $request->getContent() );
|
||||
$json = json_decode( $request->getContent(), true );
|
||||
// var_dump( $json );
|
||||
// die();
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$newSellRecord = new SellRecord();
|
||||
// sort user categories
|
||||
$myCategories = $m->getRepository( 'AppBundle:ProductCategory' )->findAll();
|
||||
$categoriesByID = [];
|
||||
foreach ( $myCategories as $my_category ) {
|
||||
$categoriesByID[ $my_category->getId() ] = $my_category;
|
||||
}
|
||||
|
||||
$productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
|
||||
$productsModelsByID = [];
|
||||
foreach ( $productsModels as $product ) {
|
||||
$productsModelsByID[ $product->getId() ] = $product;
|
||||
}
|
||||
|
||||
foreach ( $json[ 'activeSelling' ] as $record ) {
|
||||
var_dump( $categoriesByID[ $record[ 'category' ] ] );
|
||||
$newProductSold = new ProductSold();
|
||||
// $newProductSold->setCategory( $categoriesByID[ $record[ 'category' ] ] );
|
||||
$newProductSold->setName( $record[ 'name' ] );
|
||||
$newProductSold->setPrice( $record[ 'price' ] );
|
||||
$newProductSold->setProduct( $productsModelsByID[ $record[ 'id' ] ] );
|
||||
$newProductSold->setUser( $currentUser );
|
||||
$newProductSold->setSellRecords( $newSellRecord );
|
||||
// link selling record with user, festival
|
||||
// setup dates
|
||||
$currentUser->addProductsSold( $newProductSold );
|
||||
// persist all
|
||||
$m->persist( $newProductSold );
|
||||
}
|
||||
$newSellRecord->setPaidByClient( 0 );
|
||||
$newSellRecord->setAmount( 42 );
|
||||
$newSellRecord->setDate( new \DateTime() );
|
||||
// $newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
|
||||
|
||||
$currentUser->addSellRecords( $newSellRecord );
|
||||
|
||||
$m->persist( $newSellRecord );
|
||||
$m->persist( $currentUser );
|
||||
$m->flush();
|
||||
|
||||
// setup dates
|
||||
|
||||
// fetch back history of selling
|
||||
// echo "<pre>";
|
||||
// var_dump( $request->getContent() );
|
||||
//
|
||||
// echo "</pre>";
|
||||
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
|
||||
$lastSellings = $sellingRepo->find( [], [ 'id' => 'desc' ], 0, 3 );
|
||||
|
||||
// return var_dump( $request->getContent() );
|
||||
return new JsonResponse( [
|
||||
"message" => "ok",
|
||||
"recent_sellings" => [],
|
||||
"recent_sellings" => $lastSellings,
|
||||
"dump" => $json,
|
||||
] );
|
||||
}
|
||||
|
@ -10,12 +10,81 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
class ProductSold extends Product {
|
||||
|
||||
/**
|
||||
* the stack of products for one client at one time
|
||||
* @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold")
|
||||
*/
|
||||
private $sellRecords;
|
||||
public $sellRecords;
|
||||
|
||||
/**
|
||||
* person who recorded the sell
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* references the product from whom this line is inspired
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product", inversedBy="productsSold")
|
||||
*/
|
||||
private $product;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
|
||||
*/
|
||||
private $category;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCategory() {
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $category
|
||||
*/
|
||||
public function setCategory( $category ) {
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSellRecords() {
|
||||
return $this->sellRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sellRecords
|
||||
*/
|
||||
public function setSellRecords( $sellRecords ) {
|
||||
$this->sellRecords = $sellRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUser() {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $user
|
||||
*/
|
||||
public function setUser( $user ) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProduct() {
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $product
|
||||
*/
|
||||
public function setProduct( $product ) {
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,13 @@ class User extends BaseUser {
|
||||
return $this->productsSold;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function addProductsSold( $product ) {
|
||||
return $this->productsSold[] = $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $productsSold
|
||||
*/
|
||||
@ -78,6 +85,13 @@ class User extends BaseUser {
|
||||
$this->sellRecords = $sellRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sellRecords
|
||||
*/
|
||||
public function addSellRecords( $sellRecords ) {
|
||||
$this->sellRecords[] = $sellRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user