Commit b7c7a5f60d677726bb12a2b038f38a2325939557

Authored by Alexey Boroda
0 parents

first commit

Showing 1652 changed files with 107345 additions and 0 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 1652 files are displayed.

.env.testing 0 โ†’ 100755
  1 +++ a/.env.testing
  1 +APP_NAME=Akaunting
  2 +APP_ENV=testing
  3 +APP_LOCALE=en-GB
  4 +APP_INSTALLED=false
  5 +APP_KEY=base64:xBC+BxlC7sXhYAtpTZv8TYAHqoPgsJaXL0S5Id6BbBc=
  6 +APP_DEBUG=true
  7 +APP_LOG_LEVEL=debug
  8 +APP_URL=http://akaunting.test
  9 +
  10 +DB_CONNECTION=sqlite
  11 +DB_DATABASE=:memory:
  12 +DB_PREFIX=
  13 +
  14 +BROADCAST_DRIVER=log
  15 +CACHE_DRIVER=file
  16 +SESSION_DRIVER=file
  17 +QUEUE_DRIVER=database
  18 +
  19 +MAIL_DRIVER=mail
  20 +MAIL_HOST=localhost
  21 +MAIL_PORT=2525
  22 +MAIL_USERNAME=null
  23 +MAIL_PASSWORD=null
  24 +MAIL_ENCRYPTION=null
... ...
.gitignore 0 โ†’ 100644
  1 +++ a/.gitignore
  1 +/node_modules
  2 +/public/hot
  3 +/public/storage
  4 +/storage/*.key
  5 +/vendor
  6 +/.idea
  7 +/.vagrant
  8 +Homestead.json
  9 +Homestead.yaml
  10 +npm-debug.log
  11 +.env
  12 +robots.txt
  13 +_ide_helper.php
  14 +.phpstorm.meta.php
0 15 \ No newline at end of file
... ...
.htaccess 0 โ†’ 100755
  1 +++ a/.htaccess
  1 +# Prevent Directory Listing
  2 +<IfModule autoindex>
  3 + IndexIgnore *
  4 +</IfModule>
  5 +
  6 +<IfModule mod_rewrite.c>
  7 + # Prevent Directory Listing
  8 + <IfModule mod_negotiation.c>
  9 + Options -MultiViews -Indexes
  10 + </IfModule>
  11 +
  12 + RewriteEngine On
  13 +
  14 + # Prevent Direct Access to Protected Files
  15 + <FilesMatch "(?i)(^artisan$|\.env|\.log)">
  16 + Order deny,allow
  17 + Deny from all
  18 + </FilesMatch>
  19 +
  20 + # Prevent Direct Access To Protected Folders
  21 + RewriteRule ^(app|bootstrap|config|database|resources|routes|storage|tests)/(.*) / [L,R=301]
  22 +
  23 + # Prevent Direct Access To modules/vendor Folders Except Assets
  24 + RewriteRule ^(modules|vendor)/(.*)\.((?!ico|gif|jpg|jpeg|png|js|css|less|sass|font|woff|woff2|eot|ttf|svg).)*$ / [L,R=301]
  25 +
  26 + # Redirect Trailing Slashes If Not A Folder...
  27 + RewriteCond %{REQUEST_FILENAME} !-d
  28 + RewriteRule ^(.*)/$ /$1 [L,R=301]
  29 +
  30 + # Handle Front Controller...
  31 + RewriteCond %{REQUEST_FILENAME} !-d
  32 + RewriteCond %{REQUEST_FILENAME} !-f
  33 + RewriteRule ^ index.php [L]
  34 +
  35 + # Handle Authorization Header
  36 + RewriteCond %{HTTP:Authorization} .
  37 + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  38 +</IfModule>
... ...
Dockerfile 0 โ†’ 100755
  1 +++ a/Dockerfile
  1 +FROM php:apache
  2 +
  3 +RUN apt-get update && apt-get install -y zip libzip-dev libpng-dev \
  4 + && docker-php-ext-install pdo_mysql gd zip \
  5 + && rm -rf /var/lib/apt/lists/*
  6 +
  7 +# Composer installation.
  8 +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
  9 +
  10 +# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
  11 +ENV COMPOSER_ALLOW_SUPERUSER=1
  12 +RUN composer global require hirak/prestissimo --prefer-dist --no-progress --no-suggest --classmap-authoritative \
  13 + && composer clear-cache
  14 +ENV PATH="${PATH}:/root/.composer/vendor/bin"
  15 +
  16 +COPY . /var/www/html/
  17 +
  18 +# Authorize these folders to be edited
  19 +RUN chmod -R 777 /var/www/html/storage
  20 +RUN chmod -R 777 /var/www/html/bootstrap/cache
  21 +
  22 +# Allow rewrite
  23 +RUN a2enmod rewrite
... ...
LICENSE.txt 0 โ†’ 100755
  1 +++ a/LICENSE.txt
  1 + GNU GENERAL PUBLIC LICENSE
  2 + Version 3, 29 June 2007
  3 +
  4 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
  5 + Everyone is permitted to copy and distribute verbatim copies
  6 + of this license document, but changing it is not allowed.
  7 +
  8 + Preamble
  9 +
  10 + The GNU General Public License is a free, copyleft license for
  11 +software and other kinds of works.
  12 +
  13 + The licenses for most software and other practical works are designed
  14 +to take away your freedom to share and change the works. By contrast,
  15 +the GNU General Public License is intended to guarantee your freedom to
  16 +share and change all versions of a program--to make sure it remains free
  17 +software for all its users. We, the Free Software Foundation, use the
  18 +GNU General Public License for most of our software; it applies also to
  19 +any other work released this way by its authors. You can apply it to
  20 +your programs, too.
  21 +
  22 + When we speak of free software, we are referring to freedom, not
  23 +price. Our General Public Licenses are designed to make sure that you
  24 +have the freedom to distribute copies of free software (and charge for
  25 +them if you wish), that you receive source code or can get it if you
  26 +want it, that you can change the software or use pieces of it in new
  27 +free programs, and that you know you can do these things.
  28 +
  29 + To protect your rights, we need to prevent others from denying you
  30 +these rights or asking you to surrender the rights. Therefore, you have
  31 +certain responsibilities if you distribute copies of the software, or if
  32 +you modify it: responsibilities to respect the freedom of others.
  33 +
  34 + For example, if you distribute copies of such a program, whether
  35 +gratis or for a fee, you must pass on to the recipients the same
  36 +freedoms that you received. You must make sure that they, too, receive
  37 +or can get the source code. And you must show them these terms so they
  38 +know their rights.
  39 +
  40 + Developers that use the GNU GPL protect your rights with two steps:
  41 +(1) assert copyright on the software, and (2) offer you this License
  42 +giving you legal permission to copy, distribute and/or modify it.
  43 +
  44 + For the developers' and authors' protection, the GPL clearly explains
  45 +that there is no warranty for this free software. For both users' and
  46 +authors' sake, the GPL requires that modified versions be marked as
  47 +changed, so that their problems will not be attributed erroneously to
  48 +authors of previous versions.
  49 +
  50 + Some devices are designed to deny users access to install or run
  51 +modified versions of the software inside them, although the manufacturer
  52 +can do so. This is fundamentally incompatible with the aim of
  53 +protecting users' freedom to change the software. The systematic
  54 +pattern of such abuse occurs in the area of products for individuals to
  55 +use, which is precisely where it is most unacceptable. Therefore, we
  56 +have designed this version of the GPL to prohibit the practice for those
  57 +products. If such problems arise substantially in other domains, we
  58 +stand ready to extend this provision to those domains in future versions
  59 +of the GPL, as needed to protect the freedom of users.
  60 +
  61 + Finally, every program is threatened constantly by software patents.
  62 +States should not allow patents to restrict development and use of
  63 +software on general-purpose computers, but in those that do, we wish to
  64 +avoid the special danger that patents applied to a free program could
  65 +make it effectively proprietary. To prevent this, the GPL assures that
  66 +patents cannot be used to render the program non-free.
  67 +
  68 + The precise terms and conditions for copying, distribution and
  69 +modification follow.
  70 +
  71 + TERMS AND CONDITIONS
  72 +
  73 + 0. Definitions.
  74 +
  75 + "This License" refers to version 3 of the GNU General Public License.
  76 +
  77 + "Copyright" also means copyright-like laws that apply to other kinds of
  78 +works, such as semiconductor masks.
  79 +
  80 + "The Program" refers to any copyrightable work licensed under this
  81 +License. Each licensee is addressed as "you". "Licensees" and
  82 +"recipients" may be individuals or organizations.
  83 +
  84 + To "modify" a work means to copy from or adapt all or part of the work
  85 +in a fashion requiring copyright permission, other than the making of an
  86 +exact copy. The resulting work is called a "modified version" of the
  87 +earlier work or a work "based on" the earlier work.
  88 +
  89 + A "covered work" means either the unmodified Program or a work based
  90 +on the Program.
  91 +
  92 + To "propagate" a work means to do anything with it that, without
  93 +permission, would make you directly or secondarily liable for
  94 +infringement under applicable copyright law, except executing it on a
  95 +computer or modifying a private copy. Propagation includes copying,
  96 +distribution (with or without modification), making available to the
  97 +public, and in some countries other activities as well.
  98 +
  99 + To "convey" a work means any kind of propagation that enables other
  100 +parties to make or receive copies. Mere interaction with a user through
  101 +a computer network, with no transfer of a copy, is not conveying.
  102 +
  103 + An interactive user interface displays "Appropriate Legal Notices"
  104 +to the extent that it includes a convenient and prominently visible
  105 +feature that (1) displays an appropriate copyright notice, and (2)
  106 +tells the user that there is no warranty for the work (except to the
  107 +extent that warranties are provided), that licensees may convey the
  108 +work under this License, and how to view a copy of this License. If
  109 +the interface presents a list of user commands or options, such as a
  110 +menu, a prominent item in the list meets this criterion.
  111 +
  112 + 1. Source Code.
  113 +
  114 + The "source code" for a work means the preferred form of the work
  115 +for making modifications to it. "Object code" means any non-source
  116 +form of a work.
  117 +
  118 + A "Standard Interface" means an interface that either is an official
  119 +standard defined by a recognized standards body, or, in the case of
  120 +interfaces specified for a particular programming language, one that
  121 +is widely used among developers working in that language.
  122 +
  123 + The "System Libraries" of an executable work include anything, other
  124 +than the work as a whole, that (a) is included in the normal form of
  125 +packaging a Major Component, but which is not part of that Major
  126 +Component, and (b) serves only to enable use of the work with that
  127 +Major Component, or to implement a Standard Interface for which an
  128 +implementation is available to the public in source code form. A
  129 +"Major Component", in this context, means a major essential component
  130 +(kernel, window system, and so on) of the specific operating system
  131 +(if any) on which the executable work runs, or a compiler used to
  132 +produce the work, or an object code interpreter used to run it.
  133 +
  134 + The "Corresponding Source" for a work in object code form means all
  135 +the source code needed to generate, install, and (for an executable
  136 +work) run the object code and to modify the work, including scripts to
  137 +control those activities. However, it does not include the work's
  138 +System Libraries, or general-purpose tools or generally available free
  139 +programs which are used unmodified in performing those activities but
  140 +which are not part of the work. For example, Corresponding Source
  141 +includes interface definition files associated with source files for
  142 +the work, and the source code for shared libraries and dynamically
  143 +linked subprograms that the work is specifically designed to require,
  144 +such as by intimate data communication or control flow between those
  145 +subprograms and other parts of the work.
  146 +
  147 + The Corresponding Source need not include anything that users
  148 +can regenerate automatically from other parts of the Corresponding
  149 +Source.
  150 +
  151 + The Corresponding Source for a work in source code form is that
  152 +same work.
  153 +
  154 + 2. Basic Permissions.
  155 +
  156 + All rights granted under this License are granted for the term of
  157 +copyright on the Program, and are irrevocable provided the stated
  158 +conditions are met. This License explicitly affirms your unlimited
  159 +permission to run the unmodified Program. The output from running a
  160 +covered work is covered by this License only if the output, given its
  161 +content, constitutes a covered work. This License acknowledges your
  162 +rights of fair use or other equivalent, as provided by copyright law.
  163 +
  164 + You may make, run and propagate covered works that you do not
  165 +convey, without conditions so long as your license otherwise remains
  166 +in force. You may convey covered works to others for the sole purpose
  167 +of having them make modifications exclusively for you, or provide you
  168 +with facilities for running those works, provided that you comply with
  169 +the terms of this License in conveying all material for which you do
  170 +not control copyright. Those thus making or running the covered works
  171 +for you must do so exclusively on your behalf, under your direction
  172 +and control, on terms that prohibit them from making any copies of
  173 +your copyrighted material outside their relationship with you.
  174 +
  175 + Conveying under any other circumstances is permitted solely under
  176 +the conditions stated below. Sublicensing is not allowed; section 10
  177 +makes it unnecessary.
  178 +
  179 + 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
  180 +
  181 + No covered work shall be deemed part of an effective technological
  182 +measure under any applicable law fulfilling obligations under article
  183 +11 of the WIPO copyright treaty adopted on 20 December 1996, or
  184 +similar laws prohibiting or restricting circumvention of such
  185 +measures.
  186 +
  187 + When you convey a covered work, you waive any legal power to forbid
  188 +circumvention of technological measures to the extent such circumvention
  189 +is effected by exercising rights under this License with respect to
  190 +the covered work, and you disclaim any intention to limit operation or
  191 +modification of the work as a means of enforcing, against the work's
  192 +users, your or third parties' legal rights to forbid circumvention of
  193 +technological measures.
  194 +
  195 + 4. Conveying Verbatim Copies.
  196 +
  197 + You may convey verbatim copies of the Program's source code as you
  198 +receive it, in any medium, provided that you conspicuously and
  199 +appropriately publish on each copy an appropriate copyright notice;
  200 +keep intact all notices stating that this License and any
  201 +non-permissive terms added in accord with section 7 apply to the code;
  202 +keep intact all notices of the absence of any warranty; and give all
  203 +recipients a copy of this License along with the Program.
  204 +
  205 + You may charge any price or no price for each copy that you convey,
  206 +and you may offer support or warranty protection for a fee.
  207 +
  208 + 5. Conveying Modified Source Versions.
  209 +
  210 + You may convey a work based on the Program, or the modifications to
  211 +produce it from the Program, in the form of source code under the
  212 +terms of section 4, provided that you also meet all of these conditions:
  213 +
  214 + a) The work must carry prominent notices stating that you modified
  215 + it, and giving a relevant date.
  216 +
  217 + b) The work must carry prominent notices stating that it is
  218 + released under this License and any conditions added under section
  219 + 7. This requirement modifies the requirement in section 4 to
  220 + "keep intact all notices".
  221 +
  222 + c) You must license the entire work, as a whole, under this
  223 + License to anyone who comes into possession of a copy. This
  224 + License will therefore apply, along with any applicable section 7
  225 + additional terms, to the whole of the work, and all its parts,
  226 + regardless of how they are packaged. This License gives no
  227 + permission to license the work in any other way, but it does not
  228 + invalidate such permission if you have separately received it.
  229 +
  230 + d) If the work has interactive user interfaces, each must display
  231 + Appropriate Legal Notices; however, if the Program has interactive
  232 + interfaces that do not display Appropriate Legal Notices, your
  233 + work need not make them do so.
  234 +
  235 + A compilation of a covered work with other separate and independent
  236 +works, which are not by their nature extensions of the covered work,
  237 +and which are not combined with it such as to form a larger program,
  238 +in or on a volume of a storage or distribution medium, is called an
  239 +"aggregate" if the compilation and its resulting copyright are not
  240 +used to limit the access or legal rights of the compilation's users
  241 +beyond what the individual works permit. Inclusion of a covered work
  242 +in an aggregate does not cause this License to apply to the other
  243 +parts of the aggregate.
  244 +
  245 + 6. Conveying Non-Source Forms.
  246 +
  247 + You may convey a covered work in object code form under the terms
  248 +of sections 4 and 5, provided that you also convey the
  249 +machine-readable Corresponding Source under the terms of this License,
  250 +in one of these ways:
  251 +
  252 + a) Convey the object code in, or embodied in, a physical product
  253 + (including a physical distribution medium), accompanied by the
  254 + Corresponding Source fixed on a durable physical medium
  255 + customarily used for software interchange.
  256 +
  257 + b) Convey the object code in, or embodied in, a physical product
  258 + (including a physical distribution medium), accompanied by a
  259 + written offer, valid for at least three years and valid for as
  260 + long as you offer spare parts or customer support for that product
  261 + model, to give anyone who possesses the object code either (1) a
  262 + copy of the Corresponding Source for all the software in the
  263 + product that is covered by this License, on a durable physical
  264 + medium customarily used for software interchange, for a price no
  265 + more than your reasonable cost of physically performing this
  266 + conveying of source, or (2) access to copy the
  267 + Corresponding Source from a network server at no charge.
  268 +
  269 + c) Convey individual copies of the object code with a copy of the
  270 + written offer to provide the Corresponding Source. This
  271 + alternative is allowed only occasionally and noncommercially, and
  272 + only if you received the object code with such an offer, in accord
  273 + with subsection 6b.
  274 +
  275 + d) Convey the object code by offering access from a designated
  276 + place (gratis or for a charge), and offer equivalent access to the
  277 + Corresponding Source in the same way through the same place at no
  278 + further charge. You need not require recipients to copy the
  279 + Corresponding Source along with the object code. If the place to
  280 + copy the object code is a network server, the Corresponding Source
  281 + may be on a different server (operated by you or a third party)
  282 + that supports equivalent copying facilities, provided you maintain
  283 + clear directions next to the object code saying where to find the
  284 + Corresponding Source. Regardless of what server hosts the
  285 + Corresponding Source, you remain obligated to ensure that it is
  286 + available for as long as needed to satisfy these requirements.
  287 +
  288 + e) Convey the object code using peer-to-peer transmission, provided
  289 + you inform other peers where the object code and Corresponding
  290 + Source of the work are being offered to the general public at no
  291 + charge under subsection 6d.
  292 +
  293 + A separable portion of the object code, whose source code is excluded
  294 +from the Corresponding Source as a System Library, need not be
  295 +included in conveying the object code work.
  296 +
  297 + A "User Product" is either (1) a "consumer product", which means any
  298 +tangible personal property which is normally used for personal, family,
  299 +or household purposes, or (2) anything designed or sold for incorporation
  300 +into a dwelling. In determining whether a product is a consumer product,
  301 +doubtful cases shall be resolved in favor of coverage. For a particular
  302 +product received by a particular user, "normally used" refers to a
  303 +typical or common use of that class of product, regardless of the status
  304 +of the particular user or of the way in which the particular user
  305 +actually uses, or expects or is expected to use, the product. A product
  306 +is a consumer product regardless of whether the product has substantial
  307 +commercial, industrial or non-consumer uses, unless such uses represent
  308 +the only significant mode of use of the product.
  309 +
  310 + "Installation Information" for a User Product means any methods,
  311 +procedures, authorization keys, or other information required to install
  312 +and execute modified versions of a covered work in that User Product from
  313 +a modified version of its Corresponding Source. The information must
  314 +suffice to ensure that the continued functioning of the modified object
  315 +code is in no case prevented or interfered with solely because
  316 +modification has been made.
  317 +
  318 + If you convey an object code work under this section in, or with, or
  319 +specifically for use in, a User Product, and the conveying occurs as
  320 +part of a transaction in which the right of possession and use of the
  321 +User Product is transferred to the recipient in perpetuity or for a
  322 +fixed term (regardless of how the transaction is characterized), the
  323 +Corresponding Source conveyed under this section must be accompanied
  324 +by the Installation Information. But this requirement does not apply
  325 +if neither you nor any third party retains the ability to install
  326 +modified object code on the User Product (for example, the work has
  327 +been installed in ROM).
  328 +
  329 + The requirement to provide Installation Information does not include a
  330 +requirement to continue to provide support service, warranty, or updates
  331 +for a work that has been modified or installed by the recipient, or for
  332 +the User Product in which it has been modified or installed. Access to a
  333 +network may be denied when the modification itself materially and
  334 +adversely affects the operation of the network or violates the rules and
  335 +protocols for communication across the network.
  336 +
  337 + Corresponding Source conveyed, and Installation Information provided,
  338 +in accord with this section must be in a format that is publicly
  339 +documented (and with an implementation available to the public in
  340 +source code form), and must require no special password or key for
  341 +unpacking, reading or copying.
  342 +
  343 + 7. Additional Terms.
  344 +
  345 + "Additional permissions" are terms that supplement the terms of this
  346 +License by making exceptions from one or more of its conditions.
  347 +Additional permissions that are applicable to the entire Program shall
  348 +be treated as though they were included in this License, to the extent
  349 +that they are valid under applicable law. If additional permissions
  350 +apply only to part of the Program, that part may be used separately
  351 +under those permissions, but the entire Program remains governed by
  352 +this License without regard to the additional permissions.
  353 +
  354 + When you convey a copy of a covered work, you may at your option
  355 +remove any additional permissions from that copy, or from any part of
  356 +it. (Additional permissions may be written to require their own
  357 +removal in certain cases when you modify the work.) You may place
  358 +additional permissions on material, added by you to a covered work,
  359 +for which you have or can give appropriate copyright permission.
  360 +
  361 + Notwithstanding any other provision of this License, for material you
  362 +add to a covered work, you may (if authorized by the copyright holders of
  363 +that material) supplement the terms of this License with terms:
  364 +
  365 + a) Disclaiming warranty or limiting liability differently from the
  366 + terms of sections 15 and 16 of this License; or
  367 +
  368 + b) Requiring preservation of specified reasonable legal notices or
  369 + author attributions in that material or in the Appropriate Legal
  370 + Notices displayed by works containing it; or
  371 +
  372 + c) Prohibiting misrepresentation of the origin of that material, or
  373 + requiring that modified versions of such material be marked in
  374 + reasonable ways as different from the original version; or
  375 +
  376 + d) Limiting the use for publicity purposes of names of licensors or
  377 + authors of the material; or
  378 +
  379 + e) Declining to grant rights under trademark law for use of some
  380 + trade names, trademarks, or service marks; or
  381 +
  382 + f) Requiring indemnification of licensors and authors of that
  383 + material by anyone who conveys the material (or modified versions of
  384 + it) with contractual assumptions of liability to the recipient, for
  385 + any liability that these contractual assumptions directly impose on
  386 + those licensors and authors.
  387 +
  388 + All other non-permissive additional terms are considered "further
  389 +restrictions" within the meaning of section 10. If the Program as you
  390 +received it, or any part of it, contains a notice stating that it is
  391 +governed by this License along with a term that is a further
  392 +restriction, you may remove that term. If a license document contains
  393 +a further restriction but permits relicensing or conveying under this
  394 +License, you may add to a covered work material governed by the terms
  395 +of that license document, provided that the further restriction does
  396 +not survive such relicensing or conveying.
  397 +
  398 + If you add terms to a covered work in accord with this section, you
  399 +must place, in the relevant source files, a statement of the
  400 +additional terms that apply to those files, or a notice indicating
  401 +where to find the applicable terms.
  402 +
  403 + Additional terms, permissive or non-permissive, may be stated in the
  404 +form of a separately written license, or stated as exceptions;
  405 +the above requirements apply either way.
  406 +
  407 + 8. Termination.
  408 +
  409 + You may not propagate or modify a covered work except as expressly
  410 +provided under this License. Any attempt otherwise to propagate or
  411 +modify it is void, and will automatically terminate your rights under
  412 +this License (including any patent licenses granted under the third
  413 +paragraph of section 11).
  414 +
  415 + However, if you cease all violation of this License, then your
  416 +license from a particular copyright holder is reinstated (a)
  417 +provisionally, unless and until the copyright holder explicitly and
  418 +finally terminates your license, and (b) permanently, if the copyright
  419 +holder fails to notify you of the violation by some reasonable means
  420 +prior to 60 days after the cessation.
  421 +
  422 + Moreover, your license from a particular copyright holder is
  423 +reinstated permanently if the copyright holder notifies you of the
  424 +violation by some reasonable means, this is the first time you have
  425 +received notice of violation of this License (for any work) from that
  426 +copyright holder, and you cure the violation prior to 30 days after
  427 +your receipt of the notice.
  428 +
  429 + Termination of your rights under this section does not terminate the
  430 +licenses of parties who have received copies or rights from you under
  431 +this License. If your rights have been terminated and not permanently
  432 +reinstated, you do not qualify to receive new licenses for the same
  433 +material under section 10.
  434 +
  435 + 9. Acceptance Not Required for Having Copies.
  436 +
  437 + You are not required to accept this License in order to receive or
  438 +run a copy of the Program. Ancillary propagation of a covered work
  439 +occurring solely as a consequence of using peer-to-peer transmission
  440 +to receive a copy likewise does not require acceptance. However,
  441 +nothing other than this License grants you permission to propagate or
  442 +modify any covered work. These actions infringe copyright if you do
  443 +not accept this License. Therefore, by modifying or propagating a
  444 +covered work, you indicate your acceptance of this License to do so.
  445 +
  446 + 10. Automatic Licensing of Downstream Recipients.
  447 +
  448 + Each time you convey a covered work, the recipient automatically
  449 +receives a license from the original licensors, to run, modify and
  450 +propagate that work, subject to this License. You are not responsible
  451 +for enforcing compliance by third parties with this License.
  452 +
  453 + An "entity transaction" is a transaction transferring control of an
  454 +organization, or substantially all assets of one, or subdividing an
  455 +organization, or merging organizations. If propagation of a covered
  456 +work results from an entity transaction, each party to that
  457 +transaction who receives a copy of the work also receives whatever
  458 +licenses to the work the party's predecessor in interest had or could
  459 +give under the previous paragraph, plus a right to possession of the
  460 +Corresponding Source of the work from the predecessor in interest, if
  461 +the predecessor has it or can get it with reasonable efforts.
  462 +
  463 + You may not impose any further restrictions on the exercise of the
  464 +rights granted or affirmed under this License. For example, you may
  465 +not impose a license fee, royalty, or other charge for exercise of
  466 +rights granted under this License, and you may not initiate litigation
  467 +(including a cross-claim or counterclaim in a lawsuit) alleging that
  468 +any patent claim is infringed by making, using, selling, offering for
  469 +sale, or importing the Program or any portion of it.
  470 +
  471 + 11. Patents.
  472 +
  473 + A "contributor" is a copyright holder who authorizes use under this
  474 +License of the Program or a work on which the Program is based. The
  475 +work thus licensed is called the contributor's "contributor version".
  476 +
  477 + A contributor's "essential patent claims" are all patent claims
  478 +owned or controlled by the contributor, whether already acquired or
  479 +hereafter acquired, that would be infringed by some manner, permitted
  480 +by this License, of making, using, or selling its contributor version,
  481 +but do not include claims that would be infringed only as a
  482 +consequence of further modification of the contributor version. For
  483 +purposes of this definition, "control" includes the right to grant
  484 +patent sublicenses in a manner consistent with the requirements of
  485 +this License.
  486 +
  487 + Each contributor grants you a non-exclusive, worldwide, royalty-free
  488 +patent license under the contributor's essential patent claims, to
  489 +make, use, sell, offer for sale, import and otherwise run, modify and
  490 +propagate the contents of its contributor version.
  491 +
  492 + In the following three paragraphs, a "patent license" is any express
  493 +agreement or commitment, however denominated, not to enforce a patent
  494 +(such as an express permission to practice a patent or covenant not to
  495 +sue for patent infringement). To "grant" such a patent license to a
  496 +party means to make such an agreement or commitment not to enforce a
  497 +patent against the party.
  498 +
  499 + If you convey a covered work, knowingly relying on a patent license,
  500 +and the Corresponding Source of the work is not available for anyone
  501 +to copy, free of charge and under the terms of this License, through a
  502 +publicly available network server or other readily accessible means,
  503 +then you must either (1) cause the Corresponding Source to be so
  504 +available, or (2) arrange to deprive yourself of the benefit of the
  505 +patent license for this particular work, or (3) arrange, in a manner
  506 +consistent with the requirements of this License, to extend the patent
  507 +license to downstream recipients. "Knowingly relying" means you have
  508 +actual knowledge that, but for the patent license, your conveying the
  509 +covered work in a country, or your recipient's use of the covered work
  510 +in a country, would infringe one or more identifiable patents in that
  511 +country that you have reason to believe are valid.
  512 +
  513 + If, pursuant to or in connection with a single transaction or
  514 +arrangement, you convey, or propagate by procuring conveyance of, a
  515 +covered work, and grant a patent license to some of the parties
  516 +receiving the covered work authorizing them to use, propagate, modify
  517 +or convey a specific copy of the covered work, then the patent license
  518 +you grant is automatically extended to all recipients of the covered
  519 +work and works based on it.
  520 +
  521 + A patent license is "discriminatory" if it does not include within
  522 +the scope of its coverage, prohibits the exercise of, or is
  523 +conditioned on the non-exercise of one or more of the rights that are
  524 +specifically granted under this License. You may not convey a covered
  525 +work if you are a party to an arrangement with a third party that is
  526 +in the business of distributing software, under which you make payment
  527 +to the third party based on the extent of your activity of conveying
  528 +the work, and under which the third party grants, to any of the
  529 +parties who would receive the covered work from you, a discriminatory
  530 +patent license (a) in connection with copies of the covered work
  531 +conveyed by you (or copies made from those copies), or (b) primarily
  532 +for and in connection with specific products or compilations that
  533 +contain the covered work, unless you entered into that arrangement,
  534 +or that patent license was granted, prior to 28 March 2007.
  535 +
  536 + Nothing in this License shall be construed as excluding or limiting
  537 +any implied license or other defenses to infringement that may
  538 +otherwise be available to you under applicable patent law.
  539 +
  540 + 12. No Surrender of Others' Freedom.
  541 +
  542 + If conditions are imposed on you (whether by court order, agreement or
  543 +otherwise) that contradict the conditions of this License, they do not
  544 +excuse you from the conditions of this License. If you cannot convey a
  545 +covered work so as to satisfy simultaneously your obligations under this
  546 +License and any other pertinent obligations, then as a consequence you may
  547 +not convey it at all. For example, if you agree to terms that obligate you
  548 +to collect a royalty for further conveying from those to whom you convey
  549 +the Program, the only way you could satisfy both those terms and this
  550 +License would be to refrain entirely from conveying the Program.
  551 +
  552 + 13. Use with the GNU Affero General Public License.
  553 +
  554 + Notwithstanding any other provision of this License, you have
  555 +permission to link or combine any covered work with a work licensed
  556 +under version 3 of the GNU Affero General Public License into a single
  557 +combined work, and to convey the resulting work. The terms of this
  558 +License will continue to apply to the part which is the covered work,
  559 +but the special requirements of the GNU Affero General Public License,
  560 +section 13, concerning interaction through a network will apply to the
  561 +combination as such.
  562 +
  563 + 14. Revised Versions of this License.
  564 +
  565 + The Free Software Foundation may publish revised and/or new versions of
  566 +the GNU General Public License from time to time. Such new versions will
  567 +be similar in spirit to the present version, but may differ in detail to
  568 +address new problems or concerns.
  569 +
  570 + Each version is given a distinguishing version number. If the
  571 +Program specifies that a certain numbered version of the GNU General
  572 +Public License "or any later version" applies to it, you have the
  573 +option of following the terms and conditions either of that numbered
  574 +version or of any later version published by the Free Software
  575 +Foundation. If the Program does not specify a version number of the
  576 +GNU General Public License, you may choose any version ever published
  577 +by the Free Software Foundation.
  578 +
  579 + If the Program specifies that a proxy can decide which future
  580 +versions of the GNU General Public License can be used, that proxy's
  581 +public statement of acceptance of a version permanently authorizes you
  582 +to choose that version for the Program.
  583 +
  584 + Later license versions may give you additional or different
  585 +permissions. However, no additional obligations are imposed on any
  586 +author or copyright holder as a result of your choosing to follow a
  587 +later version.
  588 +
  589 + 15. Disclaimer of Warranty.
  590 +
  591 + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
  592 +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  593 +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
  594 +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
  595 +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  596 +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
  597 +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
  598 +ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  599 +
  600 + 16. Limitation of Liability.
  601 +
  602 + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  603 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
  604 +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
  605 +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  606 +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  607 +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
  608 +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
  609 +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
  610 +SUCH DAMAGES.
  611 +
  612 + 17. Interpretation of Sections 15 and 16.
  613 +
  614 + If the disclaimer of warranty and limitation of liability provided
  615 +above cannot be given local legal effect according to their terms,
  616 +reviewing courts shall apply local law that most closely approximates
  617 +an absolute waiver of all civil liability in connection with the
  618 +Program, unless a warranty or assumption of liability accompanies a
  619 +copy of the Program in return for a fee.
  620 +
  621 + END OF TERMS AND CONDITIONS
  622 +
  623 + How to Apply These Terms to Your New Programs
  624 +
  625 + If you develop a new program, and you want it to be of the greatest
  626 +possible use to the public, the best way to achieve this is to make it
  627 +free software which everyone can redistribute and change under these terms.
  628 +
  629 + To do so, attach the following notices to the program. It is safest
  630 +to attach them to the start of each source file to most effectively
  631 +state the exclusion of warranty; and each file should have at least
  632 +the "copyright" line and a pointer to where the full notice is found.
  633 +
  634 + {one line to give the program's name and a brief idea of what it does.}
  635 + Copyright (C) {year} {name of author}
  636 +
  637 + This program is free software: you can redistribute it and/or modify
  638 + it under the terms of the GNU General Public License as published by
  639 + the Free Software Foundation, either version 3 of the License, or
  640 + (at your option) any later version.
  641 +
  642 + This program is distributed in the hope that it will be useful,
  643 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  644 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  645 + GNU General Public License for more details.
  646 +
  647 + You should have received a copy of the GNU General Public License
  648 + along with this program. If not, see <http://www.gnu.org/licenses/>.
  649 +
  650 +Also add information on how to contact you by electronic and paper mail.
  651 +
  652 + If the program does terminal interaction, make it output a short
  653 +notice like this when it starts in an interactive mode:
  654 +
  655 + {project} Copyright (C) {year} {fullname}
  656 + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  657 + This is free software, and you are welcome to redistribute it
  658 + under certain conditions; type `show c' for details.
  659 +
  660 +The hypothetical commands `show w' and `show c' should show the appropriate
  661 +parts of the General Public License. Of course, your program's commands
  662 +might be different; for a GUI interface, you would use an "about box".
  663 +
  664 + You should also get your employer (if you work as a programmer) or school,
  665 +if any, to sign a "copyright disclaimer" for the program, if necessary.
  666 +For more information on this, and how to apply and follow the GNU GPL, see
  667 +<http://www.gnu.org/licenses/>.
  668 +
  669 + The GNU General Public License does not permit incorporating your program
  670 +into proprietary programs. If your program is a subroutine library, you
  671 +may consider it more useful to permit linking proprietary applications with
  672 +the library. If this is what you want to do, use the GNU Lesser General
  673 +Public License instead of this License. But first, please read
  674 +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
... ...
app/Console/Commands/BillReminder.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/BillReminder.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Common\Company;
  6 +use App\Models\Expense\Bill;
  7 +use App\Notifications\Expense\Bill as Notification;
  8 +use App\Utilities\Overrider;
  9 +use Date;
  10 +use Illuminate\Console\Command;
  11 +
  12 +class BillReminder extends Command
  13 +{
  14 + /**
  15 + * The name and signature of the console command.
  16 + *
  17 + * @var string
  18 + */
  19 + protected $signature = 'reminder:bill';
  20 +
  21 + /**
  22 + * The console command description.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $description = 'Send reminders for bills';
  27 +
  28 + /**
  29 + * Create a new command instance.
  30 + */
  31 + public function __construct()
  32 + {
  33 + parent::__construct();
  34 + }
  35 +
  36 + /**
  37 + * Execute the console command.
  38 + *
  39 + * @return mixed
  40 + */
  41 + public function handle()
  42 + {
  43 + // Get all companies
  44 + $companies = Company::all();
  45 +
  46 + foreach ($companies as $company) {
  47 + // Set company id
  48 + session(['company_id' => $company->id]);
  49 +
  50 + // Override settings and currencies
  51 + Overrider::load('settings');
  52 + Overrider::load('currencies');
  53 +
  54 + $company->setSettings();
  55 +
  56 + // Don't send reminders if disabled
  57 + if (!$company->send_bill_reminder) {
  58 + continue;
  59 + }
  60 +
  61 + $days = explode(',', $company->schedule_bill_days);
  62 +
  63 + foreach ($days as $day) {
  64 + $day = (int) trim($day);
  65 +
  66 + $this->remind($day, $company);
  67 + }
  68 + }
  69 +
  70 + // Unset company_id
  71 + session()->forget('company_id');
  72 + }
  73 +
  74 + protected function remind($day, $company)
  75 + {
  76 + // Get due date
  77 + $date = Date::today()->addDays($day)->toDateString();
  78 +
  79 + // Get upcoming bills
  80 + $bills = Bill::with('vendor')->accrued()->notPaid()->due($date)->get();
  81 +
  82 + foreach ($bills as $bill) {
  83 + // Notify all users assigned to this company
  84 + foreach ($company->users as $user) {
  85 + if (!$user->can('read-notifications')) {
  86 + continue;
  87 + }
  88 +
  89 + $user->notify(new Notification($bill));
  90 + }
  91 + }
  92 + }
  93 +}
... ...
app/Console/Commands/CompanySeed.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/CompanySeed.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use Illuminate\Console\Command;
  6 +
  7 +class CompanySeed extends Command
  8 +{
  9 + /**
  10 + * The name and signature of the console command.
  11 + *
  12 + * @var string
  13 + */
  14 + protected $signature = 'company:seed {company}';
  15 +
  16 + /**
  17 + * The console command description.
  18 + *
  19 + * @var string
  20 + */
  21 + protected $description = 'Seed for specific company';
  22 +
  23 + /**
  24 + * Create a new command instance.
  25 + *
  26 + * @return void
  27 + */
  28 + public function __construct()
  29 + {
  30 + parent::__construct();
  31 + }
  32 +
  33 + /**
  34 + * Execute the console command.
  35 + *
  36 + * @return mixed
  37 + */
  38 + public function handle()
  39 + {
  40 + $class = $this->laravel->make('CompanySeeder');
  41 +
  42 + $seeder = $class->setContainer($this->laravel)->setCommand($this);
  43 +
  44 + $seeder->__invoke();
  45 + }
  46 +
  47 +}
... ...
app/Console/Commands/Install.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/Install.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use Session;
  6 +use App\Utilities\Installer;
  7 +use Illuminate\Console\Command;
  8 +
  9 +class Install extends Command
  10 +{
  11 + const CMD_SUCCESS = 0;
  12 + const CMD_ERROR = 1;
  13 + const OPT_DB_HOST = 'db-host';
  14 + const OPT_DB_PORT = 'db-port';
  15 + const OPT_DB_NAME = 'db-name';
  16 + const OPT_DB_USERNAME = 'db-username';
  17 + const OPT_DB_PASSWORD = 'db-password';
  18 + const OPT_COMPANY_NAME = 'company-name';
  19 + const OPT_COMPANY_EMAIL = 'company-email';
  20 + const OPT_ADMIN_EMAIL = 'admin-email';
  21 + const OPT_ADMIN_PASSWORD = 'admin-password';
  22 + const OPT_LOCALE = 'locale';
  23 + const OPT_NO_INTERACTION = 'no-interaction';
  24 +
  25 + public $dbHost;
  26 + public $dbPort;
  27 + public $dbName;
  28 + public $dbUsername;
  29 + public $dbPassword;
  30 +
  31 + public $companyName;
  32 + public $companyEmail;
  33 +
  34 + public $adminEmail;
  35 + public $adminPassword;
  36 +
  37 + public $locale;
  38 +
  39 + /**
  40 + * The name and signature of the console command.
  41 + *
  42 + * @var string
  43 + */
  44 + protected $signature = 'install
  45 + {--db-host= : Database host}
  46 + {--db-port=3306 : Port of the database host}
  47 + {--db-name= : Name of the database}
  48 + {--db-username= : Username to use to access the database}
  49 + {--db-password= : Password to use to access the database}
  50 + {--company-name= : Name of the company managed buy the app}
  51 + {--company-email= : email used to contact the company}
  52 + {--admin-email= : Admin user email}
  53 + {--admin-password= : Admin user password}
  54 + {--locale=en-GB : Language used in the app}
  55 + ';
  56 +
  57 + /**
  58 + * The console command description.
  59 + *
  60 + * @var string
  61 + */
  62 + protected $description = 'Allows to install Akaunting directly through CLI';
  63 +
  64 + /**
  65 + * Create a new command instance.
  66 + */
  67 + public function __construct()
  68 + {
  69 + parent::__construct();
  70 + }
  71 +
  72 + /**
  73 + * Execute the console command.
  74 + *
  75 + * @return mixed
  76 + */
  77 + public function handle()
  78 + {
  79 + $missingOptions = $this->checkOptions();
  80 + if (!empty($missingOptions) && $this->option(self::OPT_NO_INTERACTION)) {
  81 + $this->line('โŒ Some options are missing and --no-interaction is present. Please run the following command for more informations :');
  82 + $this->line('โŒ php artisan help install');
  83 + $this->line('โŒ Missing options are : ' . join(', ', $missingOptions));
  84 +
  85 + return self::CMD_ERROR;
  86 + }
  87 +
  88 + $this->line('Setting locale ' . $this->locale);
  89 + Session::put(self::OPT_LOCALE, $this->locale);
  90 +
  91 + $this->prompt();
  92 +
  93 + // Create the .env file
  94 + Installer::createDefaultEnvFile();
  95 +
  96 + $this->line('Creating database tables');
  97 + if (!$this->createDatabaseTables()) {
  98 + return self::CMD_ERROR;
  99 + }
  100 +
  101 + $this->line('Creating company');
  102 + Installer::createCompany($this->companyName, $this->companyEmail, $this->locale);
  103 +
  104 + $this->line('Creating admin');
  105 + Installer::createUser($this->adminEmail, $this->adminPassword, $this->locale);
  106 +
  107 + $this->line('Applying the final touches');
  108 + Installer::finalTouches();
  109 +
  110 + return self::CMD_SUCCESS;
  111 + }
  112 +
  113 + /**
  114 + * Check that all options are presents. otherwise returns an array of the missing options
  115 + */
  116 + private function checkOptions()
  117 + {
  118 + $missingOptions = array();
  119 +
  120 + $this->locale = $this->option(self::OPT_LOCALE);
  121 + if (empty($this->locale)) {
  122 + $missingOptions[] = self::OPT_LOCALE;
  123 + }
  124 +
  125 + $this->dbHost = $this->option(self::OPT_DB_HOST);
  126 + if (empty($this->dbHost)) {
  127 + $missingOptions[] = self::OPT_DB_HOST;
  128 + }
  129 +
  130 + $this->dbPort = $this->option(self::OPT_DB_PORT);
  131 + if (empty($this->dbPort)) {
  132 + $missingOptions[] = self::OPT_DB_PORT;
  133 + }
  134 +
  135 + $this->dbName = $this->option(self::OPT_DB_NAME);
  136 + if (empty($this->dbPort)) {
  137 + $missingOptions[] = self::OPT_DB_NAME;
  138 + }
  139 +
  140 + $this->dbUsername = $this->option(self::OPT_DB_USERNAME);
  141 + if (empty($this->dbPort)) {
  142 + $missingOptions[] = self::OPT_DB_USERNAME;
  143 + }
  144 +
  145 + $this->dbPassword = $this->option(self::OPT_DB_PASSWORD);
  146 + if (empty($this->dbPort)) {
  147 + $missingOptions[] = self::OPT_DB_PASSWORD;
  148 + }
  149 +
  150 + $this->companyName = $this->option(self::OPT_COMPANY_NAME);
  151 + if (empty($this->dbPort)) {
  152 + $missingOptions[] = self::OPT_COMPANY_NAME;
  153 + }
  154 +
  155 + $this->companyEmail = $this->option(self::OPT_COMPANY_EMAIL);
  156 + if (empty($this->dbPort)) {
  157 + $missingOptions[] = self::OPT_COMPANY_EMAIL;
  158 + }
  159 +
  160 + $this->adminEmail = $this->option(self::OPT_ADMIN_EMAIL);
  161 + if (empty($this->dbPort)) {
  162 + $missingOptions[] = self::OPT_ADMIN_EMAIL;
  163 + }
  164 +
  165 + $this->adminPassword = $this->option(self::OPT_ADMIN_PASSWORD);
  166 + if (empty($this->dbPort)) {
  167 + $missingOptions[] = self::OPT_ADMIN_PASSWORD;
  168 + }
  169 +
  170 + return $missingOptions;
  171 + }
  172 +
  173 + /**
  174 + * Ask the user for data if some options are missing.
  175 + */
  176 + private function prompt()
  177 + {
  178 + if (empty($this->dbHost)) {
  179 + $this->dbHost = $this->ask('What is the database host?', 'localhost');
  180 + }
  181 +
  182 + if (empty($this->dbPort)) {
  183 + $this->dbPort = $this->ask('What is the database port?', '3606');
  184 + }
  185 +
  186 + if (empty($this->dbName)) {
  187 + $this->dbName = $this->ask('What is the database name?');
  188 + }
  189 +
  190 + if (empty($this->dbUsername)) {
  191 + $this->dbUsername = $this->ask('What is the database username?');
  192 + }
  193 +
  194 + if (empty($this->dbPassword)) {
  195 + $this->dbPassword = $this->secret('What is the database password?');
  196 + }
  197 +
  198 + if (empty($this->companyName)) {
  199 + $this->companyName = $this->ask('What is the company name?');
  200 + }
  201 +
  202 + if (empty($this->companyEmail)) {
  203 + $this->companyEmail = $this->ask('What is the company contact email?');
  204 + }
  205 +
  206 + if (empty($this->adminEmail)) {
  207 + $this->adminEmail = $this->ask('What is the admin email?', $this->companyEmail);
  208 + }
  209 +
  210 + if (empty($this->adminPassword)) {
  211 + $this->adminPassword = $this->secret('What is the admin password?');
  212 + }
  213 + }
  214 +
  215 + private function createDatabaseTables() {
  216 + $this->dbHost = $this->option(self::OPT_DB_HOST);
  217 + $this->dbPort = $this->option(self::OPT_DB_PORT);
  218 + $this->dbName = $this->option(self::OPT_DB_NAME);
  219 + $this->dbUsername = $this->option(self::OPT_DB_USERNAME);
  220 + $this->dbPassword = $this->option(self::OPT_DB_PASSWORD);
  221 +
  222 + $this->line('Connecting to database ' . $this->dbName . '@' . $this->dbHost . ':' . $this->dbPort);
  223 +
  224 + if (!Installer::createDbTables($this->dbHost, $this->dbPort, $this->dbName, $this->dbUsername, $this->dbPassword)) {
  225 + $this->error('Error: Could not connect to the database! Please, make sure the details are correct.');
  226 +
  227 + return false;
  228 + }
  229 +
  230 + return true;
  231 + }
  232 +}
... ...
app/Console/Commands/InvoiceReminder.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/InvoiceReminder.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Common\Company;
  6 +use App\Models\Income\Invoice;
  7 +use App\Notifications\Income\Invoice as Notification;
  8 +use App\Utilities\Overrider;
  9 +use Date;
  10 +use Illuminate\Console\Command;
  11 +
  12 +class InvoiceReminder extends Command
  13 +{
  14 + /**
  15 + * The name and signature of the console command.
  16 + *
  17 + * @var string
  18 + */
  19 + protected $signature = 'reminder:invoice';
  20 +
  21 + /**
  22 + * The console command description.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $description = 'Send reminders for invoices';
  27 +
  28 + /**
  29 + * Create a new command instance.
  30 + */
  31 + public function __construct()
  32 + {
  33 + parent::__construct();
  34 + }
  35 +
  36 + /**
  37 + * Execute the console command.
  38 + *
  39 + * @return mixed
  40 + */
  41 + public function handle()
  42 + {
  43 + // Get all companies
  44 + $companies = Company::all();
  45 +
  46 + foreach ($companies as $company) {
  47 + // Set company id
  48 + session(['company_id' => $company->id]);
  49 +
  50 + // Override settings and currencies
  51 + Overrider::load('settings');
  52 + Overrider::load('currencies');
  53 +
  54 + $company->setSettings();
  55 +
  56 + // Don't send reminders if disabled
  57 + if (!$company->send_invoice_reminder) {
  58 + continue;
  59 + }
  60 +
  61 + $days = explode(',', $company->schedule_invoice_days);
  62 +
  63 + foreach ($days as $day) {
  64 + $day = (int) trim($day);
  65 +
  66 + $this->remind($day, $company);
  67 + }
  68 + }
  69 +
  70 + // Unset company_id
  71 + session()->forget('company_id');
  72 + }
  73 +
  74 + protected function remind($day, $company)
  75 + {
  76 + // Get due date
  77 + $date = Date::today()->subDays($day)->toDateString();
  78 +
  79 + // Get upcoming bills
  80 + $invoices = Invoice::with('customer')->accrued()->notPaid()->due($date)->get();
  81 +
  82 + foreach ($invoices as $invoice) {
  83 + // Notify the customer
  84 + if ($invoice->customer && !empty($invoice->customer_email)) {
  85 + $invoice->customer->notify(new Notification($invoice));
  86 + }
  87 +
  88 + // Notify all users assigned to this company
  89 + foreach ($company->users as $user) {
  90 + if (!$user->can('read-notifications')) {
  91 + continue;
  92 + }
  93 +
  94 + $user->notify(new Notification($invoice));
  95 + }
  96 + }
  97 + }
  98 +}
... ...
app/Console/Commands/ModuleDisable.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/ModuleDisable.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Module\Module;
  6 +use App\Models\Module\ModuleHistory;
  7 +use Illuminate\Console\Command;
  8 +use Symfony\Component\Console\Input\InputArgument;
  9 +
  10 +class ModuleDisable extends Command
  11 +{
  12 + /**
  13 + * The name and signature of the console command.
  14 + *
  15 + * @var string
  16 + */
  17 + protected $signature = 'module:disable {alias} {company_id}';
  18 +
  19 + /**
  20 + * The console command description.
  21 + *
  22 + * @var string
  23 + */
  24 + protected $description = 'Disable the specified module.';
  25 +
  26 + /**
  27 + * Execute the console command.
  28 + *
  29 + * @return mixed
  30 + */
  31 + public function handle()
  32 + {
  33 + $alias = $this->argument('alias');
  34 + $company_id = $this->argument('company_id');
  35 +
  36 + $model = Module::alias($alias)->companyId($company_id)->first();
  37 +
  38 + if (!$model) {
  39 + $this->info("Module [{$alias}] not found.");
  40 + return;
  41 + }
  42 +
  43 + if ($model->status == 1) {
  44 + $model->status = 0;
  45 + $model->save();
  46 +
  47 + $module = $this->laravel['modules']->findByAlias($alias);
  48 +
  49 + // Add history
  50 + $data = [
  51 + 'company_id' => $company_id,
  52 + 'module_id' => $model->id,
  53 + 'category' => $module->get('category'),
  54 + 'version' => $module->get('version'),
  55 + 'description' => trans('modules.disabled', ['module' => $module->get('name')]),
  56 + ];
  57 +
  58 + ModuleHistory::create($data);
  59 +
  60 + $this->info("Module [{$alias}] disabled.");
  61 + } else {
  62 + $this->comment("Module [{$alias}] is already disabled.");
  63 + }
  64 + }
  65 +
  66 + /**
  67 + * Get the console command arguments.
  68 + *
  69 + * @return array
  70 + */
  71 + protected function getArguments()
  72 + {
  73 + return array(
  74 + array('alias', InputArgument::REQUIRED, 'Module alias.'),
  75 + array('company_id', InputArgument::REQUIRED, 'Company ID.'),
  76 + );
  77 + }
  78 +}
... ...
app/Console/Commands/ModuleEnable.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/ModuleEnable.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Module\Module;
  6 +use App\Models\Module\ModuleHistory;
  7 +use Illuminate\Console\Command;
  8 +use Symfony\Component\Console\Input\InputArgument;
  9 +
  10 +class ModuleEnable extends Command
  11 +{
  12 + /**
  13 + * The name and signature of the console command.
  14 + *
  15 + * @var string
  16 + */
  17 + protected $signature = 'module:enable {alias} {company_id}';
  18 +
  19 + /**
  20 + * The console command description.
  21 + *
  22 + * @var string
  23 + */
  24 + protected $description = 'Enable the specified module.';
  25 +
  26 + /**
  27 + * Execute the console command.
  28 + *
  29 + * @return mixed
  30 + */
  31 + public function handle()
  32 + {
  33 + $alias = $this->argument('alias');
  34 + $company_id = $this->argument('company_id');
  35 +
  36 + $model = Module::alias($alias)->companyId($company_id)->first();
  37 +
  38 + if (!$model) {
  39 + $this->info("Module [{$alias}] not found.");
  40 + return;
  41 + }
  42 +
  43 + if ($model->status == 0) {
  44 + $model->status = 1;
  45 + $model->save();
  46 +
  47 + $module = $this->laravel['modules']->findByAlias($alias);
  48 +
  49 + // Add history
  50 + $data = [
  51 + 'company_id' => $company_id,
  52 + 'module_id' => $model->id,
  53 + 'category' => $module->get('category'),
  54 + 'version' => $module->get('version'),
  55 + 'description' => trans('modules.enabled', ['module' => $module->get('name')]),
  56 + ];
  57 +
  58 + ModuleHistory::create($data);
  59 +
  60 + $this->info("Module [{$alias}] enabled.");
  61 + } else {
  62 + $this->comment("Module [{$alias}] is already enabled.");
  63 + }
  64 + }
  65 +
  66 + /**
  67 + * Get the console command arguments.
  68 + *
  69 + * @return array
  70 + */
  71 + protected function getArguments()
  72 + {
  73 + return array(
  74 + array('alias', InputArgument::REQUIRED, 'Module alias.'),
  75 + array('company_id', InputArgument::REQUIRED, 'Company ID.'),
  76 + );
  77 + }
  78 +}
... ...
app/Console/Commands/ModuleInstall.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/ModuleInstall.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Events\ModuleInstalled;
  6 +use App\Models\Module\Module;
  7 +use App\Models\Module\ModuleHistory;
  8 +use Illuminate\Console\Command;
  9 +use Symfony\Component\Console\Input\InputArgument;
  10 +
  11 +class ModuleInstall extends Command
  12 +{
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'module:install {alias} {company_id}';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = 'Install the specified module.';
  26 +
  27 + /**
  28 + * Execute the console command.
  29 + *
  30 + * @return mixed
  31 + */
  32 + public function handle()
  33 + {
  34 + $request = [
  35 + 'company_id' => $this->argument('company_id'),
  36 + 'alias' => strtolower($this->argument('alias')),
  37 + 'status' => '1',
  38 + ];
  39 +
  40 + $model = Module::create($request);
  41 +
  42 + $module = $this->laravel['modules']->findByAlias($model->alias);
  43 +
  44 + $company_id = $this->argument('company_id');
  45 +
  46 + // Add history
  47 + $data = [
  48 + 'company_id' => $company_id,
  49 + 'module_id' => $model->id,
  50 + 'category' => $module->get('category'),
  51 + 'version' => $module->get('version'),
  52 + 'description' => trans('modules.installed', ['module' => $module->get('name')]),
  53 + ];
  54 +
  55 + ModuleHistory::create($data);
  56 +
  57 + // Update database
  58 + $this->call('migrate', ['--force' => true]);
  59 +
  60 + // Trigger event
  61 + event(new ModuleInstalled($model->alias, $company_id));
  62 +
  63 + $this->info('Module installed!');
  64 + }
  65 +
  66 + /**
  67 + * Get the console command arguments.
  68 + *
  69 + * @return array
  70 + */
  71 + protected function getArguments()
  72 + {
  73 + return array(
  74 + array('alias', InputArgument::REQUIRED, 'Module alias.'),
  75 + array('company_id', InputArgument::REQUIRED, 'Company ID.'),
  76 + );
  77 + }
  78 +}
... ...
app/Console/Commands/RecurringCheck.php 0 โ†’ 100755
  1 +++ a/app/Console/Commands/RecurringCheck.php
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Common\Company;
  6 +use App\Models\Expense\BillHistory;
  7 +use App\Models\Income\InvoiceHistory;
  8 +use App\Notifications\Expense\Bill as BillNotification;
  9 +use App\Notifications\Income\Invoice as InvoiceNotification;
  10 +use App\Traits\Incomes;
  11 +use App\Utilities\Overrider;
  12 +use Date;
  13 +use Illuminate\Console\Command;
  14 +use Recurr\Rule;
  15 +use Recurr\Transformer\ArrayTransformer;
  16 +use Recurr\Transformer\ArrayTransformerConfig;
  17 +
  18 +class RecurringCheck extends Command
  19 +{
  20 + use Incomes;
  21 +
  22 + /**
  23 + * The name and signature of the console command.
  24 + *
  25 + * @var string
  26 + */
  27 + protected $signature = 'recurring:check';
  28 +
  29 + /**
  30 + * The console command description.
  31 + *
  32 + * @var string
  33 + */
  34 + protected $description = 'Check for recurring';
  35 +
  36 + /**
  37 + * Create a new command instance.
  38 + */
  39 + public function __construct()
  40 + {
  41 + parent::__construct();
  42 + }
  43 +
  44 + /**
  45 + * Execute the console command.
  46 + *
  47 + * @return mixed
  48 + */
  49 + public function handle()
  50 + {
  51 + $this->today = Date::today();
  52 +
  53 + // Get all companies
  54 + $companies = Company::all();
  55 +
  56 + foreach ($companies as $company) {
  57 + // Set company id
  58 + session(['company_id' => $company->id]);
  59 +
  60 + // Override settings and currencies
  61 + Overrider::load('settings');
  62 + Overrider::load('currencies');
  63 +
  64 + $company->setSettings();
  65 +
  66 + foreach ($company->recurring as $recur) {
  67 + if (!$current = $recur->current()) {
  68 + continue;
  69 + }
  70 +
  71 + $current_date = Date::parse($current->format('Y-m-d'));
  72 +
  73 + // Check if should recur today
  74 + if ($this->today->ne($current_date)) {
  75 + continue;
  76 + }
  77 +
  78 + $model = $recur->recurable;
  79 +
  80 + if (!$model) {
  81 + continue;
  82 + }
  83 +
  84 + switch ($recur->recurable_type) {
  85 + case 'App\Models\Expense\Bill':
  86 + $this->recurBill($company, $model);
  87 + break;
  88 + case 'App\Models\Income\Invoice':
  89 + $this->recurInvoice($company, $model);
  90 + break;
  91 + case 'App\Models\Expense\Payment':
  92 + case 'App\Models\Income\Revenue':
  93 + $model->cloneable_relations = [];
  94 +
  95 + // Create new record
  96 + $clone = $model->duplicate();
  97 +
  98 + $clone->parent_id = $model->id;
  99 + $clone->paid_at = $this->today->format('Y-m-d');
  100 + $clone->save();
  101 +
  102 + break;
  103 + }
  104 + }
  105 + }
  106 +
  107 + // Unset company_id
  108 + session()->forget('company_id');
  109 + }
  110 +
  111 + protected function recurInvoice($company, $model)
  112 + {
  113 + $model->cloneable_relations = ['items', 'totals'];
  114 +
  115 + // Create new record
  116 + $clone = $model->duplicate();
  117 +
  118 + // Set original invoice id
  119 + $clone->parent_id = $model->id;
  120 +
  121 + // Days between invoiced and due date
  122 + $diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
  123 +
  124 + // Update dates
  125 + $clone->invoiced_at = $this->today->format('Y-m-d');
  126 + $clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
  127 + $clone->save();
  128 +
  129 + // Add invoice history
  130 + InvoiceHistory::create([
  131 + 'company_id' => session('company_id'),
  132 + 'invoice_id' => $clone->id,
  133 + 'status_code' => 'draft',
  134 + 'notify' => 0,
  135 + 'description' => trans('messages.success.added', ['type' => $clone->invoice_number]),
  136 + ]);
  137 +
  138 + // Notify the customer
  139 + if ($clone->customer && !empty($clone->customer_email)) {
  140 + $clone->customer->notify(new InvoiceNotification($clone));
  141 + }
  142 +
  143 + // Notify all users assigned to this company
  144 + foreach ($company->users as $user) {
  145 + if (!$user->can('read-notifications')) {
  146 + continue;
  147 + }
  148 +
  149 + $user->notify(new InvoiceNotification($clone));
  150 + }
  151 +
  152 + // Update next invoice number
  153 + $this->increaseNextInvoiceNumber();
  154 + }
  155 +
  156 + protected function recurBill($company, $model)
  157 + {
  158 + $model->cloneable_relations = ['items', 'totals'];
  159 +
  160 + // Create new record
  161 + $clone = $model->duplicate();
  162 +
  163 + // Set original bill id
  164 + $clone->parent_id = $model->id;
  165 +
  166 + // Days between invoiced and due date
  167 + $diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
  168 +
  169 + // Update dates
  170 + $clone->billed_at = $this->today->format('Y-m-d');
  171 + $clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
  172 + $clone->save();
  173 +
  174 + // Add bill history
  175 + BillHistory::create([
  176 + 'company_id' => session('company_id'),
  177 + 'bill_id' => $clone->id,
  178 + 'status_code' => 'draft',
  179 + 'notify' => 0,
  180 + 'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
  181 + ]);
  182 +
  183 + // Notify all users assigned to this company
  184 + foreach ($company->users as $user) {
  185 + if (!$user->can('read-notifications')) {
  186 + continue;
  187 + }
  188 +
  189 + $user->notify(new BillNotification($clone));
  190 + }
  191 + }
  192 +}
... ...
app/Console/Kernel.php 0 โ†’ 100755
  1 +++ a/app/Console/Kernel.php
  1 +<?php
  2 +
  3 +namespace App\Console;
  4 +
  5 +use Illuminate\Console\Scheduling\Schedule;
  6 +use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  7 +
  8 +class Kernel extends ConsoleKernel
  9 +{
  10 + /**
  11 + * The Artisan commands provided by your application.
  12 + *
  13 + * @var array
  14 + */
  15 + protected $commands = [
  16 + Commands\CompanySeed::class,
  17 + Commands\BillReminder::class,
  18 + Commands\Install::class,
  19 + Commands\InvoiceReminder::class,
  20 + Commands\ModuleDisable::class,
  21 + Commands\ModuleEnable::class,
  22 + Commands\ModuleInstall::class,
  23 + Commands\RecurringCheck::class,
  24 + ];
  25 +
  26 + /**
  27 + * Define the application's command schedule.
  28 + *
  29 + * @param \Illuminate\Console\Scheduling\Schedule $schedule
  30 + * @return void
  31 + */
  32 + protected function schedule(Schedule $schedule)
  33 + {
  34 + // Not installed yet
  35 + if (!env('APP_INSTALLED')) {
  36 + return;
  37 + }
  38 +
  39 + $schedule->command('reminder:invoice')->dailyAt(setting('general.schedule_time', '09:00'));
  40 + $schedule->command('reminder:bill')->dailyAt(setting('general.schedule_time', '09:00'));
  41 + $schedule->command('recurring:check')->dailyAt(setting('general.schedule_time', '09:00'));
  42 + }
  43 +
  44 + /**
  45 + * Register the Closure based commands for the application.
  46 + *
  47 + * @return void
  48 + */
  49 + protected function commands()
  50 + {
  51 + require base_path('routes/console.php');
  52 + }
  53 +}
... ...
app/Console/Stubs/Modules/command.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/command.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Console\Command;
  6 +use Symfony\Component\Console\Input\InputOption;
  7 +use Symfony\Component\Console\Input\InputArgument;
  8 +
  9 +class $CLASS$ extends Command
  10 +{
  11 + /**
  12 + * The console command name.
  13 + *
  14 + * @var string
  15 + */
  16 + protected $name = '$COMMAND_NAME$';
  17 +
  18 + /**
  19 + * The console command description.
  20 + *
  21 + * @var string
  22 + */
  23 + protected $description = 'Command description.';
  24 +
  25 + /**
  26 + * Create a new command instance.
  27 + *
  28 + * @return void
  29 + */
  30 + public function __construct()
  31 + {
  32 + parent::__construct();
  33 + }
  34 +
  35 + /**
  36 + * Execute the console command.
  37 + *
  38 + * @return mixed
  39 + */
  40 + public function fire()
  41 + {
  42 + //
  43 + }
  44 +
  45 + /**
  46 + * Get the console command arguments.
  47 + *
  48 + * @return array
  49 + */
  50 + protected function getArguments()
  51 + {
  52 + return [
  53 + ['example', InputArgument::REQUIRED, 'An example argument.'],
  54 + ];
  55 + }
  56 +
  57 + /**
  58 + * Get the console command options.
  59 + *
  60 + * @return array
  61 + */
  62 + protected function getOptions()
  63 + {
  64 + return [
  65 + ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
  66 + ];
  67 + }
  68 +}
... ...
app/Console/Stubs/Modules/composer.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/composer.stub
  1 +{
  2 + "name": "$VENDOR$/$LOWER_NAME$",
  3 + "description": "",
  4 + "authors": [
  5 + {
  6 + "name": "$AUTHOR_NAME$",
  7 + "email": "$AUTHOR_EMAIL$"
  8 + }
  9 + ],
  10 + "autoload": {
  11 + "psr-4": {
  12 + "$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
  13 + }
  14 + }
  15 +}
... ...
app/Console/Stubs/Modules/controller-plain.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/controller-plain.stub
  1 +<?php
  2 +
  3 +namespace $CLASS_NAMESPACE$;
  4 +
  5 +use Illuminate\Routing\Controller;
  6 +
  7 +class $CLASS$ extends Controller
  8 +{
  9 +}
... ...
app/Console/Stubs/Modules/controller.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/controller.stub
  1 +<?php
  2 +
  3 +namespace $CLASS_NAMESPACE$;
  4 +
  5 +use Illuminate\Http\Request;
  6 +use Illuminate\Http\Response;
  7 +use Illuminate\Routing\Controller;
  8 +
  9 +class $CLASS$ extends Controller
  10 +{
  11 + /**
  12 + * Display a listing of the resource.
  13 + * @return Response
  14 + */
  15 + public function index()
  16 + {
  17 + return view('$LOWER_NAME$::index');
  18 + }
  19 +
  20 + /**
  21 + * Show the form for creating a new resource.
  22 + * @return Response
  23 + */
  24 + public function create()
  25 + {
  26 + return view('$LOWER_NAME$::create');
  27 + }
  28 +
  29 + /**
  30 + * Store a newly created resource in storage.
  31 + * @param Request $request
  32 + * @return Response
  33 + */
  34 + public function store(Request $request)
  35 + {
  36 + }
  37 +
  38 + /**
  39 + * Show the specified resource.
  40 + * @return Response
  41 + */
  42 + public function show()
  43 + {
  44 + return view('$LOWER_NAME$::show');
  45 + }
  46 +
  47 + /**
  48 + * Show the form for editing the specified resource.
  49 + * @return Response
  50 + */
  51 + public function edit()
  52 + {
  53 + return view('$LOWER_NAME$::edit');
  54 + }
  55 +
  56 + /**
  57 + * Update the specified resource in storage.
  58 + * @param Request $request
  59 + * @return Response
  60 + */
  61 + public function update(Request $request)
  62 + {
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + * @return Response
  68 + */
  69 + public function destroy()
  70 + {
  71 + }
  72 +}
... ...
app/Console/Stubs/Modules/event.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/event.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Queue\SerializesModels;
  6 +
  7 +class $CLASS$
  8 +{
  9 + use SerializesModels;
  10 +
  11 + /**
  12 + * Create a new event instance.
  13 + *
  14 + * @return void
  15 + */
  16 + public function __construct()
  17 + {
  18 + //
  19 + }
  20 +
  21 + /**
  22 + * Get the channels the event should be broadcast on.
  23 + *
  24 + * @return array
  25 + */
  26 + public function broadcastOn()
  27 + {
  28 + return [];
  29 + }
  30 +}
... ...
app/Console/Stubs/Modules/job.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/job.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Queue\SerializesModels;
  6 +use Illuminate\Queue\InteractsWithQueue;
  7 +use Illuminate\Contracts\Queue\ShouldQueue;
  8 +use Illuminate\Bus\Queueable;
  9 +
  10 +class $CLASS$ implements ShouldQueue
  11 +{
  12 + use InteractsWithQueue, SerializesModels, Queueable;
  13 +
  14 + /**
  15 + * Create a new job instance.
  16 + *
  17 + * @return void
  18 + */
  19 + public function __construct()
  20 + {
  21 + //
  22 + }
  23 +
  24 + /**
  25 + * Execute the job.
  26 + *
  27 + * @return void
  28 + */
  29 + public function handle()
  30 + {
  31 + //
  32 + }
  33 +}
... ...
app/Console/Stubs/Modules/json.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/json.stub
  1 +{
  2 + "name": "$STUDLY_NAME$",
  3 + "alias": "$LOWER_NAME$",
  4 + "description": "",
  5 + "version": "1.0.0",
  6 + "category": "payment-gateway",
  7 + "keywords": [],
  8 + "active": 1,
  9 + "order": 0,
  10 + "providers": [
  11 + "$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider"
  12 + ],
  13 + "aliases": {},
  14 + "files": [
  15 + "start.php"
  16 + ],
  17 + "requires": [],
  18 + "settings": []
  19 +}
... ...
app/Console/Stubs/Modules/listener.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/listener.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use $EVENTNAME$;
  6 +use Illuminate\Queue\InteractsWithQueue;
  7 +use Illuminate\Contracts\Queue\ShouldQueue;
  8 +
  9 +class $CLASS$
  10 +{
  11 + /**
  12 + * Create the event listener.
  13 + *
  14 + * @return void
  15 + */
  16 + public function __construct()
  17 + {
  18 + //
  19 + }
  20 +
  21 + /**
  22 + * Handle the event.
  23 + *
  24 + * @param \$EVENTNAME$ $event
  25 + * @return void
  26 + */
  27 + public function handle(\$EVENTNAME$ $event)
  28 + {
  29 + //
  30 + }
  31 +}
... ...
app/Console/Stubs/Modules/mail.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/mail.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Bus\Queueable;
  6 +use Illuminate\Mail\Mailable;
  7 +use Illuminate\Queue\SerializesModels;
  8 +use Illuminate\Contracts\Queue\ShouldQueue;
  9 +
  10 +class $CLASS$ extends Mailable
  11 +{
  12 + use Queueable, SerializesModels;
  13 +
  14 + /**
  15 + * Create a new message instance.
  16 + *
  17 + * @return void
  18 + */
  19 + public function __construct()
  20 + {
  21 + //
  22 + }
  23 +
  24 + /**
  25 + * Build the message.
  26 + *
  27 + * @return $this
  28 + */
  29 + public function build()
  30 + {
  31 + return $this->view('view.name');
  32 + }
  33 +}
... ...
app/Console/Stubs/Modules/middleware.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/middleware.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Closure;
  6 +use Illuminate\Http\Request;
  7 +
  8 +class $CLASS$
  9 +{
  10 + /**
  11 + * Handle an incoming request.
  12 + *
  13 + * @param \Illuminate\Http\Request $request
  14 + * @param \Closure $next
  15 + * @return mixed
  16 + */
  17 + public function handle(Request $request, Closure $next)
  18 + {
  19 + return $next($request);
  20 + }
  21 +}
... ...
app/Console/Stubs/Modules/migration/add.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/migration/add.stub
  1 +<?php
  2 +
  3 +use Illuminate\Support\Facades\Schema;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Database\Migrations\Migration;
  6 +
  7 +class $CLASS$ extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::table('$TABLE$', function (Blueprint $table) {
  17 +$FIELDS_UP$
  18 + });
  19 + }
  20 +
  21 + /**
  22 + * Reverse the migrations.
  23 + *
  24 + * @return void
  25 + */
  26 + public function down()
  27 + {
  28 + Schema::table('$TABLE$', function (Blueprint $table) {
  29 +$FIELDS_DOWN$
  30 + });
  31 + }
  32 +}
... ...
app/Console/Stubs/Modules/migration/create.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/migration/create.stub
  1 +<?php
  2 +
  3 +use Illuminate\Support\Facades\Schema;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Database\Migrations\Migration;
  6 +
  7 +class $CLASS$ extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::create('$TABLE$', function (Blueprint $table) {
  17 + $table->increments('id');
  18 +$FIELDS$
  19 + $table->timestamps();
  20 + });
  21 + }
  22 +
  23 + /**
  24 + * Reverse the migrations.
  25 + *
  26 + * @return void
  27 + */
  28 + public function down()
  29 + {
  30 + Schema::dropIfExists('$TABLE$');
  31 + }
  32 +}
... ...
app/Console/Stubs/Modules/migration/delete.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/migration/delete.stub
  1 +<?php
  2 +
  3 +use Illuminate\Support\Facades\Schema;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Database\Migrations\Migration;
  6 +
  7 +class $CLASS$ extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::table('$TABLE$', function (Blueprint $table) {
  17 +$FIELDS_UP$
  18 + });
  19 + }
  20 +
  21 + /**
  22 + * Reverse the migrations.
  23 + *
  24 + * @return void
  25 + */
  26 + public function down()
  27 + {
  28 + Schema::table('$TABLE$', function (Blueprint $table) {
  29 +$FIELDS_DOWN$
  30 + });
  31 + }
  32 +}
... ...
app/Console/Stubs/Modules/migration/drop.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/migration/drop.stub
  1 +<?php
  2 +
  3 +use Illuminate\Support\Facades\Schema;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Database\Migrations\Migration;
  6 +
  7 +class $CLASS$ extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::dropIfExists('$TABLE$');
  17 + }
  18 +
  19 + /**
  20 + * Reverse the migrations.
  21 + *
  22 + * @return void
  23 + */
  24 + public function down()
  25 + {
  26 + Schema::create('$TABLE$', function (Blueprint $table) {
  27 + $table->increments('id');
  28 +$FIELDS$
  29 + $table->timestamps();
  30 + });
  31 + }
  32 +}
... ...
app/Console/Stubs/Modules/migration/plain.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/migration/plain.stub
  1 +<?php
  2 +
  3 +use Illuminate\Support\Facades\Schema;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Database\Migrations\Migration;
  6 +
  7 +class $CLASS$ extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + //
  17 + }
  18 +
  19 + /**
  20 + * Reverse the migrations.
  21 + *
  22 + * @return void
  23 + */
  24 + public function down()
  25 + {
  26 + //
  27 + }
  28 +}
... ...
app/Console/Stubs/Modules/model.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/model.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Database\Eloquent\Model;
  6 +
  7 +class $CLASS$ extends Model
  8 +{
  9 + protected $fillable = $FILLABLE$;
  10 +}
... ...
app/Console/Stubs/Modules/notification.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/notification.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Bus\Queueable;
  6 +use Illuminate\Notifications\Notification;
  7 +use Illuminate\Contracts\Queue\ShouldQueue;
  8 +use Illuminate\Notifications\Messages\MailMessage;
  9 +
  10 +class $CLASS$ extends Notification
  11 +{
  12 + use Queueable;
  13 +
  14 + /**
  15 + * Create a new notification instance.
  16 + *
  17 + * @return void
  18 + */
  19 + public function __construct()
  20 + {
  21 + //
  22 + }
  23 +
  24 + /**
  25 + * Get the notification's delivery channels.
  26 + *
  27 + * @param mixed $notifiable
  28 + * @return array
  29 + */
  30 + public function via($notifiable)
  31 + {
  32 + return ['mail'];
  33 + }
  34 +
  35 + /**
  36 + * Get the mail representation of the notification.
  37 + *
  38 + * @param mixed $notifiable
  39 + * @return \Illuminate\Notifications\Messages\MailMessage
  40 + */
  41 + public function toMail($notifiable)
  42 + {
  43 + return (new MailMessage)
  44 + ->line('The introduction to the notification.')
  45 + ->action('Notification Action', 'https://laravel.com')
  46 + ->line('Thank you for using our application!');
  47 + }
  48 +
  49 + /**
  50 + * Get the array representation of the notification.
  51 + *
  52 + * @param mixed $notifiable
  53 + * @return array
  54 + */
  55 + public function toArray($notifiable)
  56 + {
  57 + return [
  58 + //
  59 + ];
  60 + }
  61 +}
... ...
app/Console/Stubs/Modules/provider.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/provider.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Support\ServiceProvider;
  6 +
  7 +class $CLASS$ extends ServiceProvider
  8 +{
  9 + /**
  10 + * Indicates if loading of the provider is deferred.
  11 + *
  12 + * @var bool
  13 + */
  14 + protected $defer = false;
  15 +
  16 + /**
  17 + * Register the service provider.
  18 + *
  19 + * @return void
  20 + */
  21 + public function register()
  22 + {
  23 + //
  24 + }
  25 +
  26 + /**
  27 + * Get the services provided by the provider.
  28 + *
  29 + * @return array
  30 + */
  31 + public function provides()
  32 + {
  33 + return [];
  34 + }
  35 +}
... ...
app/Console/Stubs/Modules/request.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/request.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class $CLASS$ extends FormRequest
  8 +{
  9 + /**
  10 + * Get the validation rules that apply to the request.
  11 + *
  12 + * @return array
  13 + */
  14 + public function rules()
  15 + {
  16 + return [
  17 + //
  18 + ];
  19 + }
  20 +
  21 + /**
  22 + * Determine if the user is authorized to make this request.
  23 + *
  24 + * @return bool
  25 + */
  26 + public function authorize()
  27 + {
  28 + return true;
  29 + }
  30 +}
... ...
app/Console/Stubs/Modules/route-provider.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/route-provider.stub
  1 +<?php
  2 +
  3 +namespace $MODULE_NAMESPACE$\$MODULE$\Providers;
  4 +
  5 +use Illuminate\Routing\Router;
  6 +use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  7 +
  8 +class $NAME$ extends ServiceProvider
  9 +{
  10 + /**
  11 + * The root namespace to assume when generating URLs to actions.
  12 + *
  13 + * @var string
  14 + */
  15 + protected $rootUrlNamespace = '$MODULE_NAMESPACE$\$MODULE$\Http\Controllers';
  16 +
  17 + /**
  18 + * Called before routes are registered.
  19 + *
  20 + * Register any model bindings or pattern based filters.
  21 + *
  22 + * @param Router $router
  23 + * @return void
  24 + */
  25 + public function before(Router $router)
  26 + {
  27 + //
  28 + }
  29 +
  30 + /**
  31 + * Define the routes for the application.
  32 + *
  33 + * @return void
  34 + */
  35 + public function map(Router $router)
  36 + {
  37 + // if (!app()->routesAreCached()) {
  38 + // require __DIR__ . '/Http/routes.php';
  39 + // }
  40 + }
  41 +}
... ...
app/Console/Stubs/Modules/routes.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/routes.stub
  1 +<?php
  2 +
  3 +Route::group(['middleware' => 'web', 'prefix' => '$LOWER_NAME$', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
  4 +{
  5 + Route::get('/', '$STUDLY_NAME$Controller@index');
  6 +});
... ...
app/Console/Stubs/Modules/scaffold/config.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/scaffold/config.stub
  1 +<?php
  2 +
  3 +return [
  4 +
  5 + 'name' => '$STUDLY_NAME$',
  6 +
  7 +];
... ...
app/Console/Stubs/Modules/scaffold/provider.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/scaffold/provider.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$;
  4 +
  5 +use Illuminate\Support\ServiceProvider;
  6 +use Illuminate\Database\Eloquent\Factory;
  7 +
  8 +class $CLASS$ extends ServiceProvider
  9 +{
  10 + /**
  11 + * Indicates if loading of the provider is deferred.
  12 + *
  13 + * @var bool
  14 + */
  15 + protected $defer = false;
  16 +
  17 + /**
  18 + * Boot the application events.
  19 + *
  20 + * @return void
  21 + */
  22 + public function boot()
  23 + {
  24 + $this->registerTranslations();
  25 + $this->registerConfig();
  26 + $this->registerViews();
  27 + $this->registerFactories();
  28 + }
  29 +
  30 + /**
  31 + * Register the service provider.
  32 + *
  33 + * @return void
  34 + */
  35 + public function register()
  36 + {
  37 + //
  38 + }
  39 +
  40 + /**
  41 + * Register config.
  42 + *
  43 + * @return void
  44 + */
  45 + protected function registerConfig()
  46 + {
  47 + $this->publishes([
  48 + __DIR__.'/../$PATH_CONFIG$/config.php' => config_path('$LOWER_NAME$.php'),
  49 + ], 'config');
  50 + $this->mergeConfigFrom(
  51 + __DIR__.'/../$PATH_CONFIG$/config.php', '$LOWER_NAME$'
  52 + );
  53 + }
  54 +
  55 + /**
  56 + * Register views.
  57 + *
  58 + * @return void
  59 + */
  60 + public function registerViews()
  61 + {
  62 + $viewPath = resource_path('views/modules/$LOWER_NAME$');
  63 +
  64 + $sourcePath = __DIR__.'/../$PATH_VIEWS$';
  65 +
  66 + $this->publishes([
  67 + $sourcePath => $viewPath
  68 + ]);
  69 +
  70 + $this->loadViewsFrom(array_merge(array_map(function ($path) {
  71 + return $path . '/modules/$LOWER_NAME$';
  72 + }, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$');
  73 + }
  74 +
  75 + /**
  76 + * Register translations.
  77 + *
  78 + * @return void
  79 + */
  80 + public function registerTranslations()
  81 + {
  82 + $langPath = resource_path('lang/modules/$LOWER_NAME$');
  83 +
  84 + if (is_dir($langPath)) {
  85 + $this->loadTranslationsFrom($langPath, '$LOWER_NAME$');
  86 + } else {
  87 + $this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$');
  88 + }
  89 + }
  90 +
  91 + /**
  92 + * Register an additional directory of factories.
  93 + * @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66
  94 + */
  95 + public function registerFactories()
  96 + {
  97 + if (! app()->environment('production')) {
  98 + app(Factory::class)->load(__DIR__ . '/Database/factories');
  99 + }
  100 + }
  101 +
  102 + /**
  103 + * Get the services provided by the provider.
  104 + *
  105 + * @return array
  106 + */
  107 + public function provides()
  108 + {
  109 + return [];
  110 + }
  111 +}
... ...
app/Console/Stubs/Modules/seeder.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/seeder.stub
  1 +<?php
  2 +
  3 +namespace $NAMESPACE$\Database\Seeders;
  4 +
  5 +use Illuminate\Database\Seeder;
  6 +use Illuminate\Database\Eloquent\Model;
  7 +
  8 +class $NAME$ extends Seeder
  9 +{
  10 + /**
  11 + * Run the database seeds.
  12 + *
  13 + * @return void
  14 + */
  15 + public function run()
  16 + {
  17 + Model::unguard();
  18 +
  19 + // $this->call("OthersTableSeeder");
  20 + }
  21 +}
... ...
app/Console/Stubs/Modules/start.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/start.stub
  1 +<?php
  2 +
  3 +/*
  4 +|--------------------------------------------------------------------------
  5 +| Register Namespaces And Routes
  6 +|--------------------------------------------------------------------------
  7 +|
  8 +| When a module starting, this file will executed automatically. This helps
  9 +| to register some namespaces like translator or view. Also this file
  10 +| will load the routes file for each module. You may also modify
  11 +| this file as you want.
  12 +|
  13 +*/
  14 +
  15 +if (!app()->routesAreCached()) {
  16 + require __DIR__ . '/Http/routes.php';
  17 +}
... ...
app/Console/Stubs/Modules/views/index.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/views/index.stub
  1 +@extends('$LOWER_NAME$::layouts.master')
  2 +
  3 +@section('content')
  4 + <h1>Hello World</h1>
  5 +
  6 + <p>
  7 + This view is loaded from module: {!! config('$LOWER_NAME$.name') !!}
  8 + </p>
  9 +@stop
... ...
app/Console/Stubs/Modules/views/master.stub 0 โ†’ 100755
  1 +++ a/app/Console/Stubs/Modules/views/master.stub
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 + <head>
  4 + <meta charset="utf-8">
  5 + <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6 + <meta name="viewport" content="width=device-width, initial-scale=1">
  7 + <title>Module $STUDLY_NAME$</title>
  8 + </head>
  9 + <body>
  10 + @yield('content')
  11 + </body>
  12 +</html>
... ...
app/Events/AdminMenuCreated.php 0 โ†’ 100755
  1 +++ a/app/Events/AdminMenuCreated.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class AdminMenuCreated
  6 +{
  7 + public $menu;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $menu
  13 + */
  14 + public function __construct($menu)
  15 + {
  16 + $this->menu = $menu;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/BillCreated.php 0 โ†’ 100755
  1 +++ a/app/Events/BillCreated.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class BillCreated
  6 +{
  7 + public $bill;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $bill
  13 + */
  14 + public function __construct($bill)
  15 + {
  16 + $this->bill = $bill;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/BillUpdated.php 0 โ†’ 100755
  1 +++ a/app/Events/BillUpdated.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class BillUpdated
  6 +{
  7 + public $bill;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $bill
  13 + */
  14 + public function __construct($bill)
  15 + {
  16 + $this->bill = $bill;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/CompanySwitched.php 0 โ†’ 100755
  1 +++ a/app/Events/CompanySwitched.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class CompanySwitched
  6 +{
  7 + public $company;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $company
  13 + */
  14 + public function __construct($company)
  15 + {
  16 + $this->company = $company;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/CustomerMenuCreated.php 0 โ†’ 100755
  1 +++ a/app/Events/CustomerMenuCreated.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class CustomerMenuCreated
  6 +{
  7 + public $menu;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $menu
  13 + */
  14 + public function __construct($menu)
  15 + {
  16 + $this->menu = $menu;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/InvoiceCreated.php 0 โ†’ 100755
  1 +++ a/app/Events/InvoiceCreated.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class InvoiceCreated
  6 +{
  7 + public $invoice;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $invoice
  13 + */
  14 + public function __construct($invoice)
  15 + {
  16 + $this->invoice = $invoice;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/InvoicePaid.php 0 โ†’ 100755
  1 +++ a/app/Events/InvoicePaid.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class InvoicePaid
  6 +{
  7 + public $invoice;
  8 +
  9 + public $request;
  10 +
  11 + /**
  12 + * Create a new event instance.
  13 + *
  14 + * @param $invoice
  15 + */
  16 + public function __construct($invoice, $request)
  17 + {
  18 + $this->invoice = $invoice;
  19 + $this->request = $request;
  20 + }
  21 +}
... ...
app/Events/InvoicePrinting.php 0 โ†’ 100755
  1 +++ a/app/Events/InvoicePrinting.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class InvoicePrinting
  6 +{
  7 + public $invoice;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $invoice
  13 + */
  14 + public function __construct($invoice)
  15 + {
  16 + $this->invoice = $invoice;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/InvoiceUpdated.php 0 โ†’ 100755
  1 +++ a/app/Events/InvoiceUpdated.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class InvoiceUpdated
  6 +{
  7 + public $invoice;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $invoice
  13 + */
  14 + public function __construct($invoice)
  15 + {
  16 + $this->invoice = $invoice;
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
app/Events/ModuleInstalled.php 0 โ†’ 100755
  1 +++ a/app/Events/ModuleInstalled.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class ModuleInstalled
  6 +{
  7 + public $alias;
  8 +
  9 + public $company_id;
  10 +
  11 + /**
  12 + * Create a new event instance.
  13 + *
  14 + * @param $alias
  15 + * @param $company_id
  16 + */
  17 + public function __construct($alias, $company_id)
  18 + {
  19 + $this->alias = $alias;
  20 + $this->company_id = $company_id;
  21 + }
  22 +}
0 23 \ No newline at end of file
... ...
app/Events/PaymentGatewayListing.php 0 โ†’ 100755
  1 +++ a/app/Events/PaymentGatewayListing.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class PaymentGatewayListing
  6 +{
  7 + public $gateways;
  8 +
  9 + /**
  10 + * Create a new event instance.
  11 + *
  12 + * @param $gateways
  13 + */
  14 + public function __construct($gateways)
  15 + {
  16 + $this->gateways = $gateways;
  17 + }
  18 +}
... ...
app/Events/UpdateFinished.php 0 โ†’ 100755
  1 +++ a/app/Events/UpdateFinished.php
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +class UpdateFinished
  6 +{
  7 + public $alias;
  8 +
  9 + public $old;
  10 +
  11 + public $new;
  12 +
  13 + /**
  14 + * Create a new event instance.
  15 + *
  16 + * @param $alias
  17 + * @param $old
  18 + * @param $new
  19 + */
  20 + public function __construct($alias, $old, $new)
  21 + {
  22 + $this->alias = $alias;
  23 + $this->old = $old;
  24 + $this->new = $new;
  25 + }
  26 +}
0 27 \ No newline at end of file
... ...
app/Exceptions/Handler.php 0 โ†’ 100755
  1 +++ a/app/Exceptions/Handler.php
  1 +<?php
  2 +
  3 +namespace App\Exceptions;
  4 +
  5 +use Exception;
  6 +use Illuminate\Auth\AuthenticationException;
  7 +use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  8 +
  9 +class Handler extends ExceptionHandler
  10 +{
  11 + /**
  12 + * A list of the exception types that should not be reported.
  13 + *
  14 + * @var array
  15 + */
  16 + protected $dontReport = [
  17 + \Illuminate\Auth\AuthenticationException::class,
  18 + \Illuminate\Auth\Access\AuthorizationException::class,
  19 + \Symfony\Component\HttpKernel\Exception\HttpException::class,
  20 + \Illuminate\Database\Eloquent\ModelNotFoundException::class,
  21 + \Illuminate\Session\TokenMismatchException::class,
  22 + \Illuminate\Validation\ValidationException::class,
  23 + ];
  24 +
  25 + /**
  26 + * Report or log an exception.
  27 + *
  28 + * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  29 + *
  30 + * @param \Exception $exception
  31 + * @return void
  32 + */
  33 + public function report(Exception $exception)
  34 + {
  35 + parent::report($exception);
  36 + }
  37 +
  38 + /**
  39 + * Render an exception into an HTTP response.
  40 + *
  41 + * @param \Illuminate\Http\Request $request
  42 + * @param \Exception $exception
  43 + * @return \Illuminate\Http\Response
  44 + */
  45 + public function render($request, Exception $exception)
  46 + {
  47 + return parent::render($request, $exception);
  48 + }
  49 +
  50 + /**
  51 + * Convert an authentication exception into an unauthenticated response.
  52 + *
  53 + * @param \Illuminate\Http\Request $request
  54 + * @param \Illuminate\Auth\AuthenticationException $exception
  55 + * @return \Illuminate\Http\Response
  56 + */
  57 + protected function unauthenticated($request, AuthenticationException $exception)
  58 + {
  59 + if ($request->expectsJson()) {
  60 + return response()->json(['error' => 'Unauthenticated.'], 401);
  61 + }
  62 +
  63 + return redirect()->guest(route('login'));
  64 + }
  65 +}
... ...
app/Filters/Auth/Permissions.php 0 โ†’ 100755
  1 +++ a/app/Filters/Auth/Permissions.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Auth;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Permissions extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('display_name', $query);
  20 + }
  21 +}
0 22 \ No newline at end of file
... ...
app/Filters/Auth/Roles.php 0 โ†’ 100755
  1 +++ a/app/Filters/Auth/Roles.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Auth;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Roles extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('display_name', $query);
  20 + }
  21 +}
0 22 \ No newline at end of file
... ...
app/Filters/Auth/Users.php 0 โ†’ 100755
  1 +++ a/app/Filters/Auth/Users.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Auth;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Users extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->where('name', 'LIKE', '%' . $query . '%')->orWhere('email', 'LIKE', '%' . $query . '%');
  20 + }
  21 +
  22 + public function role($id)
  23 + {
  24 + return $this->related('roles', 'role_id', $id);
  25 + }
  26 +}
0 27 \ No newline at end of file
... ...
app/Filters/Banking/Accounts.php 0 โ†’ 100755
  1 +++ a/app/Filters/Banking/Accounts.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Banking;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Accounts extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('name', $query);
  20 + }
  21 +}
0 22 \ No newline at end of file
... ...
app/Filters/Banking/Transactions.php 0 โ†’ 100755
  1 +++ a/app/Filters/Banking/Transactions.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Banking;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Transactions extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function account($account_id)
  18 + {
  19 + return $this->where('account_id', $account_id);
  20 + }
  21 +
  22 + public function category($category_id)
  23 + {
  24 + // No category for bills/invoices
  25 + if (in_array($this->getModel()->getTable(), ['bill_payments', 'invoice_payments'])) {
  26 + return $this;
  27 + }
  28 +
  29 + return $this->where('category_id', $category_id);
  30 + }
  31 +}
0 32 \ No newline at end of file
... ...
app/Filters/Banking/Transfers.php 0 โ†’ 100755
  1 +++ a/app/Filters/Banking/Transfers.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Banking;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Transfers extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function fromAccount($account_id)
  18 + {
  19 + return $this->where('payments.account_id', $account_id);
  20 + }
  21 +
  22 + public function toAccount($account_id)
  23 + {
  24 + return $this->related('revenue', 'revenues.account_id', '=', $account_id);
  25 + }
  26 +}
... ...
app/Filters/Common/Companies.php 0 โ†’ 100755
  1 +++ a/app/Filters/Common/Companies.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Common;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Companies extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('domain', $query);
  20 + }
  21 +}
0 22 \ No newline at end of file
... ...
app/Filters/Common/Items.php 0 โ†’ 100755
  1 +++ a/app/Filters/Common/Items.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Common;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Items extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('name', $query);
  20 + }
  21 +
  22 + public function category($id)
  23 + {
  24 + return $this->where('category_id', $id);
  25 + }
  26 +}
... ...
app/Filters/Customers/Invoices.php 0 โ†’ 100755
  1 +++ a/app/Filters/Customers/Invoices.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Customers;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Invoices extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('customer_name', $query);
  20 + }
  21 +
  22 + public function status($status)
  23 + {
  24 + return $this->where('invoice_status_code', $status);
  25 + }
  26 +}
0 27 \ No newline at end of file
... ...
app/Filters/Customers/Payments.php 0 โ†’ 100755
  1 +++ a/app/Filters/Customers/Payments.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Customers;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Payments extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('description', $query);
  20 + }
  21 +
  22 + public function category($category)
  23 + {
  24 + return $this->where('category_id', $category);
  25 + }
  26 +
  27 + public function paymentMethod($payment_method)
  28 + {
  29 + return $this->where('payment_method', $payment_method);
  30 + }
  31 +}
... ...
app/Filters/Customers/Transactions.php 0 โ†’ 100755
  1 +++ a/app/Filters/Customers/Transactions.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Customers;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Transactions extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('payment.name', $query)->whereLike('revenue.name', $query);
  20 + }
  21 +}
0 22 \ No newline at end of file
... ...
app/Filters/Expenses/Bills.php 0 โ†’ 100755
  1 +++ a/app/Filters/Expenses/Bills.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Expenses;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Bills extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('vendor_name', $query);
  20 + }
  21 +
  22 + public function vendor($vendor)
  23 + {
  24 + return $this->where('vendor_id', $vendor);
  25 + }
  26 +
  27 + public function status($status)
  28 + {
  29 + return $this->where('bill_status_code', $status);
  30 + }
  31 +}
0 32 \ No newline at end of file
... ...
app/Filters/Expenses/Payments.php 0 โ†’ 100755
  1 +++ a/app/Filters/Expenses/Payments.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Expenses;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Payments extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('description', $query);
  20 + }
  21 +
  22 + public function vendor($vendor)
  23 + {
  24 + return $this->where('vendor_id', $vendor);
  25 + }
  26 +
  27 + public function category($category)
  28 + {
  29 + return $this->where('category_id', $category);
  30 + }
  31 +
  32 + public function account($account)
  33 + {
  34 + return $this->where('account_id', $account);
  35 + }
  36 +}
0 37 \ No newline at end of file
... ...
app/Filters/Expenses/Vendors.php 0 โ†’ 100755
  1 +++ a/app/Filters/Expenses/Vendors.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Expenses;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Vendors extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->where('name', 'LIKE', '%' . $query . '%')->orWhere('email', 'LIKE', '%' . $query . '%');
  20 + }
  21 +}
0 22 \ No newline at end of file
... ...
app/Filters/Incomes/Customers.php 0 โ†’ 100755
  1 +++ a/app/Filters/Incomes/Customers.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Incomes;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Customers extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->where('name', 'LIKE', '%' . $query . '%')->orWhere('email', 'LIKE', '%' . $query . '%');
  20 + }
  21 +}
... ...
app/Filters/Incomes/Invoices.php 0 โ†’ 100755
  1 +++ a/app/Filters/Incomes/Invoices.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Incomes;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Invoices extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('customer_name', $query);
  20 + }
  21 +
  22 + public function customer($customer)
  23 + {
  24 + return $this->where('customer_id', $customer);
  25 + }
  26 +
  27 + public function status($status)
  28 + {
  29 + return $this->where('invoice_status_code', $status);
  30 + }
  31 +}
0 32 \ No newline at end of file
... ...
app/Filters/Incomes/Revenues.php 0 โ†’ 100755
  1 +++ a/app/Filters/Incomes/Revenues.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Incomes;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Revenues extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('description', $query);
  20 + }
  21 +
  22 + public function customer($customer)
  23 + {
  24 + return $this->where('customer_id', $customer);
  25 + }
  26 +
  27 + public function category($category)
  28 + {
  29 + return $this->where('category_id', $category);
  30 + }
  31 +
  32 + public function account($account)
  33 + {
  34 + return $this->where('account_id', $account);
  35 + }
  36 +}
0 37 \ No newline at end of file
... ...
app/Filters/Settings/Categories.php 0 โ†’ 100755
  1 +++ a/app/Filters/Settings/Categories.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Settings;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Categories extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('name', $query);
  20 + }
  21 +
  22 + public function type($type)
  23 + {
  24 + return $this->where('type', $type);
  25 + }
  26 +}
... ...
app/Filters/Settings/Currencies.php 0 โ†’ 100755
  1 +++ a/app/Filters/Settings/Currencies.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Settings;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Currencies extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('name', $query);
  20 + }
  21 +}
... ...
app/Filters/Settings/Taxes.php 0 โ†’ 100755
  1 +++ a/app/Filters/Settings/Taxes.php
  1 +<?php
  2 +
  3 +namespace App\Filters\Settings;
  4 +
  5 +use EloquentFilter\ModelFilter;
  6 +
  7 +class Taxes extends ModelFilter
  8 +{
  9 + /**
  10 + * Related Models that have ModelFilters as well as the method on the ModelFilter
  11 + * As [relatedModel => [input_key1, input_key2]].
  12 + *
  13 + * @var array
  14 + */
  15 + public $relations = [];
  16 +
  17 + public function search($query)
  18 + {
  19 + return $this->whereLike('name', $query);
  20 + }
  21 +}
... ...
app/Http/Controllers/Api/Auth/Permissions.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Auth/Permissions.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Auth;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Auth\Permission as Request;
  7 +use App\Models\Auth\Permission;
  8 +use App\Transformers\Auth\Permission as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Permissions extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $permissions = Permission::collect();
  23 +
  24 + return $this->response->paginator($permissions, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Permission $permission
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Permission $permission)
  34 + {
  35 + return $this->response->item($permission, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $permission = Permission::create($request->all());
  47 +
  48 + return $this->response->created(url('api/permissions/'.$permission->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $permission
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Permission $permission, Request $request)
  59 + {
  60 + $permission->update($request->all());
  61 +
  62 + return $this->response->item($permission->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Permission $permission
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Permission $permission)
  72 + {
  73 + $permission->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/Api/Auth/Roles.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Auth/Roles.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Auth;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Auth\Role as Request;
  7 +use App\Models\Auth\Role;
  8 +use App\Transformers\Auth\Role as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Roles extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $roles = Role::with('permissions')->collect();
  23 +
  24 + return $this->response->paginator($roles, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Role $role
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Role $role)
  34 + {
  35 + return $this->response->item($role, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $role = Role::create($request->input());
  47 +
  48 + if ($request->has('permissions')) {
  49 + $role->permissions()->attach($request->get('permissions'));
  50 + }
  51 +
  52 + return $this->response->created(url('api/roles/'.$role->id));
  53 + }
  54 +
  55 + /**
  56 + * Update the specified resource in storage.
  57 + *
  58 + * @param $role
  59 + * @param $request
  60 + * @return \Dingo\Api\Http\Response
  61 + */
  62 + public function update(Role $role, Request $request)
  63 + {
  64 + $role->update($request->all());
  65 +
  66 + if ($request->has('permissions')) {
  67 + $role->permissions()->attach($request->get('permissions'));
  68 + }
  69 +
  70 + return $this->response->item($role->fresh(), new Transformer());
  71 + }
  72 +
  73 + /**
  74 + * Remove the specified resource from storage.
  75 + *
  76 + * @param Role $role
  77 + * @return \Dingo\Api\Http\Response
  78 + */
  79 + public function destroy(Role $role)
  80 + {
  81 + $role->delete();
  82 +
  83 + return $this->response->noContent();
  84 + }
  85 +}
... ...
app/Http/Controllers/Api/Auth/Users.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Auth/Users.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Auth;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Auth\User as Request;
  7 +use App\Models\Auth\User;
  8 +use App\Transformers\Auth\User as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Users extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $users = User::with(['companies', 'roles', 'permissions'])->collect();
  23 +
  24 + return $this->response->paginator($users, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param int|string $id
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show($id)
  34 + {
  35 + // Check if we're querying by id or email
  36 + if (is_numeric($id)) {
  37 + $user = User::with(['companies', 'roles', 'permissions'])->find($id);
  38 + } else {
  39 + $user = User::with(['companies', 'roles', 'permissions'])->where('email', $id)->first();
  40 + }
  41 +
  42 + return $this->response->item($user, new Transformer());
  43 + }
  44 +
  45 + /**
  46 + * Store a newly created resource in storage.
  47 + *
  48 + * @param $request
  49 + * @return \Dingo\Api\Http\Response
  50 + */
  51 + public function store(Request $request)
  52 + {
  53 + $user = User::create($request->input());
  54 +
  55 + // Attach roles
  56 + $user->roles()->attach($request->get('roles'));
  57 +
  58 + // Attach companies
  59 + $user->companies()->attach($request->get('companies'));
  60 +
  61 + return $this->response->created(url('api/users/'.$user->id));
  62 + }
  63 +
  64 + /**
  65 + * Update the specified resource in storage.
  66 + *
  67 + * @param $user
  68 + * @param $request
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function update(User $user, Request $request)
  72 + {
  73 + // Except password as we don't want to let the users change a password from this endpoint
  74 + $user->update($request->except('password'));
  75 +
  76 + // Sync roles
  77 + $user->roles()->sync($request->get('roles'));
  78 +
  79 + // Sync companies
  80 + $user->companies()->sync($request->get('companies'));
  81 +
  82 + return $this->response->item($user->fresh(), new Transformer());
  83 + }
  84 +
  85 + /**
  86 + * Remove the specified resource from storage.
  87 + *
  88 + * @param User $user
  89 + * @return \Dingo\Api\Http\Response
  90 + */
  91 + public function destroy(User $user)
  92 + {
  93 + $user->delete();
  94 +
  95 + return $this->response->noContent();
  96 + }
  97 +}
... ...
app/Http/Controllers/Api/Banking/Accounts.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Banking/Accounts.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Banking;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Banking\Account as Request;
  7 +use App\Models\Banking\Account;
  8 +use App\Transformers\Banking\Account as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Accounts extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $accounts = Account::collect();
  23 +
  24 + return $this->response->paginator($accounts, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Account $account
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Account $account)
  34 + {
  35 + return $this->response->item($account, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $account = Account::create($request->all());
  47 +
  48 + return $this->response->created(url('api/accounts/'.$account->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $account
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Account $account, Request $request)
  59 + {
  60 + $account->update($request->all());
  61 +
  62 + return $this->response->item($account->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Account $account
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Account $account)
  72 + {
  73 + $account->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/Api/Banking/Transfers.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Banking/Transfers.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Banking;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Banking\Transfer as Request;
  7 +use App\Models\Banking\Transfer;
  8 +use App\Models\Expense\Payment;
  9 +use App\Models\Income\Revenue;
  10 +use App\Transformers\Banking\Transfer as Transformer;
  11 +use Dingo\Api\Routing\Helpers;
  12 +
  13 +class Transfers extends ApiController
  14 +{
  15 + use Helpers;
  16 +
  17 + /**
  18 + * Display a listing of the resource.
  19 + *
  20 + * @return \Dingo\Api\Http\Response
  21 + */
  22 + public function index()
  23 + {
  24 + $transfers = Transfer::with(['payment', 'revenue'])->collect('payment.paid_at');
  25 +
  26 + return $this->response->paginator($transfers, new Transformer());
  27 + }
  28 +
  29 + /**
  30 + * Display the specified resource.
  31 + *
  32 + * @param Transfer $transfer
  33 + * @return \Dingo\Api\Http\Response
  34 + */
  35 + public function show(Transfer $transfer)
  36 + {
  37 + return $this->response->item($transfer, new Transformer());
  38 + }
  39 +
  40 + /**
  41 + * Store a newly created resource in storage.
  42 + *
  43 + * @param $request
  44 + * @return \Dingo\Api\Http\Response
  45 + */
  46 + public function store(Request $request)
  47 + {
  48 + $transfer = Transfer::create($request->all());
  49 +
  50 + return $this->response->created(url('api/transfers/'.$transfer->id));
  51 + }
  52 +
  53 + /**
  54 + * Update the specified resource in storage.
  55 + *
  56 + * @param $transfer
  57 + * @param $request
  58 + * @return \Dingo\Api\Http\Response
  59 + */
  60 + public function update(Transfer $transfer, Request $request)
  61 + {
  62 + $transfer->update($request->all());
  63 +
  64 + return $this->response->item($transfer->fresh(), new Transformer());
  65 + }
  66 +
  67 + /**
  68 + * Remove the specified resource from storage.
  69 + *
  70 + * @param Transfer $transfer
  71 + * @return \Dingo\Api\Http\Response
  72 + */
  73 + public function destroy(Transfer $transfer)
  74 + {
  75 + $payment = Payment::findOrFail($transfer['payment_id']);
  76 + $revenue = Revenue::findOrFail($transfer['revenue_id']);
  77 +
  78 + $transfer->delete();
  79 + $payment->delete();
  80 + $revenue->delete();
  81 +
  82 + return $this->response->noContent();
  83 + }
  84 +}
... ...
app/Http/Controllers/Api/Common/Companies.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Common/Companies.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Common;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Common\Company as Request;
  7 +use App\Models\Common\Company;
  8 +use App\Transformers\Common\Company as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Companies extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $companies = app('Dingo\Api\Auth\Auth')->user()->companies()->get()->sortBy('name');
  23 +
  24 + foreach ($companies as $company) {
  25 + $company->setSettings();
  26 + }
  27 +
  28 + return $this->response->collection($companies, new Transformer());
  29 + }
  30 +
  31 + /**
  32 + * Display the specified resource.
  33 + *
  34 + * @param Company $company
  35 + * @return \Dingo\Api\Http\Response
  36 + */
  37 + public function show(Company $company)
  38 + {
  39 + // Check if user can access company
  40 + $companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
  41 + if (!in_array($company->id, $companies)) {
  42 + $this->response->errorUnauthorized();
  43 + }
  44 +
  45 + $company->setSettings();
  46 +
  47 + return $this->response->item($company, new Transformer());
  48 + }
  49 +
  50 + /**
  51 + * Store a newly created resource in storage.
  52 + *
  53 + * @param $request
  54 + * @return \Dingo\Api\Http\Response
  55 + */
  56 + public function store(Request $request)
  57 + {
  58 + // Clear settings
  59 + setting()->forgetAll();
  60 +
  61 + $company = Company::create($request->all());
  62 +
  63 + // Create settings
  64 + setting()->set([
  65 + 'general.company_name' => $request->get('company_name'),
  66 + 'general.company_email' => $request->get('company_email'),
  67 + 'general.company_address' => $request->get('company_address'),
  68 + 'general.default_currency' => $request->get('default_currency'),
  69 + 'general.default_locale' => $request->get('default_locale', 'en-GB'),
  70 + ]);
  71 +
  72 + setting()->setExtraColumns(['company_id' => $company->id]);
  73 +
  74 + setting()->save();
  75 +
  76 + return $this->response->created(url('api/companies/'.$company->id));
  77 + }
  78 +
  79 + /**
  80 + * Update the specified resource in storage.
  81 + *
  82 + * @param $company
  83 + * @param $request
  84 + * @return \Dingo\Api\Http\Response
  85 + */
  86 + public function update(Company $company, Request $request)
  87 + {
  88 + // Check if user can access company
  89 + $companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
  90 + if (!in_array($company->id, $companies)) {
  91 + $this->response->errorUnauthorized();
  92 + }
  93 +
  94 + // Update company
  95 + $company->update(['domain' => $request->get('domain')]);
  96 +
  97 + // Update settings
  98 + setting()->forgetAll();
  99 + setting()->setExtraColumns(['company_id' => $company->id]);
  100 + setting()->load(true);
  101 +
  102 + setting()->set([
  103 + 'general.company_name' => $request->get('company_name'),
  104 + 'general.company_email' => $request->get('company_email'),
  105 + 'general.company_address' => $request->get('company_address'),
  106 + 'general.default_currency' => $request->get('default_currency'),
  107 + 'general.default_locale' => $request->get('default_locale', 'en-GB'),
  108 + ]);
  109 +
  110 + setting()->save();
  111 +
  112 + return $this->response->item($company->fresh(), new Transformer());
  113 + }
  114 +
  115 + /**
  116 + * Remove the specified resource from storage.
  117 + *
  118 + * @param Company $company
  119 + * @return \Dingo\Api\Http\Response
  120 + */
  121 + public function destroy(Company $company)
  122 + {
  123 + // Check if user can access company
  124 + $companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
  125 + if (!in_array($company->id, $companies)) {
  126 + $this->response->errorUnauthorized();
  127 + }
  128 +
  129 + $company->delete();
  130 +
  131 + return $this->response->noContent();
  132 + }
  133 +}
... ...
app/Http/Controllers/Api/Common/Items.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Common/Items.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Common;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Common\Item as Request;
  7 +use App\Models\Common\Item;
  8 +use App\Transformers\Common\Item as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Items extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $items = Item::with(['category', 'tax'])->collect();
  23 +
  24 + return $this->response->paginator($items, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param int|string $id
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show($id)
  34 + {
  35 + // Check if we're querying by id or sku
  36 + if (is_numeric($id)) {
  37 + $item = Item::with(['category', 'tax'])->find($id);
  38 + } else {
  39 + $item = Item::with(['category', 'tax'])->where('sku', $id)->first();
  40 + }
  41 +
  42 + return $this->response->item($item, new Transformer());
  43 + }
  44 +
  45 + /**
  46 + * Store a newly created resource in storage.
  47 + *
  48 + * @param $request
  49 + * @return \Dingo\Api\Http\Response
  50 + */
  51 + public function store(Request $request)
  52 + {
  53 + $item = Item::create($request->all());
  54 +
  55 + return $this->response->created(url('api/items/'.$item->id));
  56 + }
  57 +
  58 + /**
  59 + * Update the specified resource in storage.
  60 + *
  61 + * @param $item
  62 + * @param $request
  63 + * @return \Dingo\Api\Http\Response
  64 + */
  65 + public function update(Item $item, Request $request)
  66 + {
  67 + $item->update($request->all());
  68 +
  69 + return $this->response->item($item->fresh(), new Transformer());
  70 + }
  71 +
  72 + /**
  73 + * Remove the specified resource from storage.
  74 + *
  75 + * @param Item $item
  76 + * @return \Dingo\Api\Http\Response
  77 + */
  78 + public function destroy(Item $item)
  79 + {
  80 + $item->delete();
  81 +
  82 + return $this->response->noContent();
  83 + }
  84 +}
... ...
app/Http/Controllers/Api/Common/Ping.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Common/Ping.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Common;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use Date;
  7 +use Dingo\Api\Routing\Helpers;
  8 +
  9 +class Ping extends ApiController
  10 +{
  11 + use Helpers;
  12 +
  13 + /**
  14 + * Responds with a status for heath check.
  15 + *
  16 + * @return \Illuminate\Http\JsonResponse
  17 + */
  18 + public function index()
  19 + {
  20 + return $this->response->array([
  21 + 'status' => 'ok',
  22 + 'timestamp' => Date::now(),
  23 + ]);
  24 + }
  25 +}
... ...
app/Http/Controllers/Api/Expenses/Bills.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Expenses/Bills.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Expenses;
  4 +
  5 +use App\Events\BillCreated;
  6 +use App\Events\BillUpdated;
  7 +use App\Http\Controllers\ApiController;
  8 +use App\Http\Requests\Expense\Bill as Request;
  9 +use App\Models\Expense\Bill;
  10 +use App\Models\Expense\BillHistory;
  11 +use App\Models\Expense\BillItem;
  12 +use App\Models\Expense\BillPayment;
  13 +use App\Models\Expense\BillStatus;
  14 +use App\Models\Common\Item;
  15 +use App\Models\Setting\Tax;
  16 +use App\Transformers\Expense\Bill as Transformer;
  17 +use Dingo\Api\Routing\Helpers;
  18 +
  19 +class Bills extends ApiController
  20 +{
  21 + use Helpers;
  22 +
  23 + /**
  24 + * Display a listing of the resource.
  25 + *
  26 + * @return \Dingo\Api\Http\Response
  27 + */
  28 + public function index()
  29 + {
  30 + $bills = Bill::with(['vendor', 'status', 'items', 'payments', 'histories'])->collect();
  31 +
  32 + return $this->response->paginator($bills, new Transformer());
  33 + }
  34 +
  35 + /**
  36 + * Display the specified resource.
  37 + *
  38 + * @param Bill $bill
  39 + * @return \Dingo\Api\Http\Response
  40 + */
  41 + public function show(Bill $bill)
  42 + {
  43 + return $this->response->item($bill, new Transformer());
  44 + }
  45 +
  46 + /**
  47 + * Store a newly created resource in storage.
  48 + *
  49 + * @param $request
  50 + * @return \Dingo\Api\Http\Response
  51 + */
  52 + public function store(Request $request)
  53 + {
  54 + $bill = Bill::create($request->all());
  55 +
  56 + $bill_item = array();
  57 + $bill_item['company_id'] = $request['company_id'];
  58 + $bill_item['bill_id'] = $bill->id;
  59 +
  60 + if ($request['item']) {
  61 + foreach ($request['item'] as $item) {
  62 + $item_id = 0;
  63 + $item_sku = '';
  64 +
  65 + if (!empty($item['item_id'])) {
  66 + $item_object = Item::find($item['item_id']);
  67 +
  68 + $item_id = $item['item_id'];
  69 +
  70 + $item['name'] = $item_object->name;
  71 + $item_sku = $item_object->sku;
  72 +
  73 + // Increase stock (item bought)
  74 + $item_object->quantity += $item['quantity'];
  75 + $item_object->save();
  76 + } elseif (!empty($item['sku'])) {
  77 + $item_sku = $item['sku'];
  78 + }
  79 +
  80 + $tax = $tax_id = 0;
  81 +
  82 + if (!empty($item['tax_id'])) {
  83 + $tax_object = Tax::find($item['tax_id']);
  84 +
  85 + $tax_id = $item['tax_id'];
  86 +
  87 + $tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
  88 + } elseif (!empty($item['tax'])) {
  89 + $tax = $item['tax'];
  90 + }
  91 +
  92 + $bill_item['item_id'] = $item_id;
  93 + $bill_item['name'] = str_limit($item['name'], 180, '');
  94 + $bill_item['sku'] = $item_sku;
  95 + $bill_item['quantity'] = $item['quantity'];
  96 + $bill_item['price'] = $item['price'];
  97 + $bill_item['tax'] = $tax;
  98 + $bill_item['tax_id'] = $tax_id;
  99 + $bill_item['total'] = ($item['price'] + $bill_item['tax']) * $item['quantity'];
  100 +
  101 + $request['amount'] += $bill_item['total'];
  102 +
  103 + BillItem::create($bill_item);
  104 + }
  105 + }
  106 +
  107 + $bill->update($request->input());
  108 +
  109 + $request['bill_id'] = $bill->id;
  110 + $request['status_code'] = $request['bill_status_code'];
  111 + $request['notify'] = 0;
  112 + $request['description'] = trans('messages.success.added', ['type' => $request['bill_number']]);
  113 +
  114 + BillHistory::create($request->input());
  115 +
  116 + // Fire the event to make it extendible
  117 + event(new BillCreated($bill));
  118 +
  119 + return $this->response->created(url('api/bills/'.$bill->id));
  120 + }
  121 +
  122 + /**
  123 + * Update the specified resource in storage.
  124 + *
  125 + * @param $bill
  126 + * @param $request
  127 + * @return \Dingo\Api\Http\Response
  128 + */
  129 + public function update(Bill $bill, Request $request)
  130 + {
  131 + $bill_item = array();
  132 + $bill_item['company_id'] = $request['company_id'];
  133 + $bill_item['bill_id'] = $bill->id;
  134 +
  135 + if ($request['item']) {
  136 + BillItem::where('bill_id', $bill->id)->delete();
  137 +
  138 + foreach ($request['item'] as $item) {
  139 + $item_id = 0;
  140 + $item_sku = '';
  141 +
  142 + if (!empty($item['item_id'])) {
  143 + $item_object = Item::find($item['item_id']);
  144 +
  145 + $item_id = $item['item_id'];
  146 +
  147 + $item['name'] = $item_object->name;
  148 + $item_sku = $item_object->sku;
  149 + } elseif (!empty($item['sku'])) {
  150 + $item_sku = $item['sku'];
  151 + }
  152 +
  153 + $tax = $tax_id = 0;
  154 +
  155 + if (!empty($item['tax_id'])) {
  156 + $tax_object = Tax::find($item['tax_id']);
  157 +
  158 + $tax_id = $item['tax_id'];
  159 +
  160 + $tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
  161 + } elseif (!empty($item['tax'])) {
  162 + $tax = $item['tax'];
  163 + }
  164 +
  165 + $bill_item['item_id'] = $item_id;
  166 + $bill_item['name'] = str_limit($item['name'], 180, '');
  167 + $bill_item['sku'] = $item_sku;
  168 + $bill_item['quantity'] = $item['quantity'];
  169 + $bill_item['price'] = $item['price'];
  170 + $bill_item['tax'] = $tax;
  171 + $bill_item['tax_id'] = $tax_id;
  172 + $bill_item['total'] = ($item['price'] + $bill_item['tax']) * $item['quantity'];
  173 +
  174 + $request['amount'] += $bill_item['total'];
  175 +
  176 + BillItem::create($bill_item);
  177 + }
  178 + }
  179 +
  180 + $bill->update($request->input());
  181 +
  182 + // Fire the event to make it extendible
  183 + event(new BillUpdated($bill));
  184 +
  185 + return $this->response->item($bill->fresh(), new Transformer());
  186 + }
  187 +
  188 + /**
  189 + * Remove the specified resource from storage.
  190 + *
  191 + * @param Bill $bill
  192 + * @return \Dingo\Api\Http\Response
  193 + */
  194 + public function destroy(Bill $bill)
  195 + {
  196 + $bill->delete();
  197 +
  198 + BillItem::where('bill_id', $bill->id)->delete();
  199 + BillPayment::where('bill_id', $bill->id)->delete();
  200 + BillHistory::where('bill_id', $bill->id)->delete();
  201 +
  202 + return $this->response->noContent();
  203 + }
  204 +}
... ...
app/Http/Controllers/Api/Expenses/Payments.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Expenses/Payments.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Expenses;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Expense\Payment as Request;
  7 +use App\Models\Expense\Payment;
  8 +use App\Transformers\Expense\Payment as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Payments extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $payments = Payment::with(['account', 'vendor', 'category'])->collect();
  23 +
  24 + return $this->response->paginator($payments, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Payment $payment
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Payment $payment)
  34 + {
  35 + return $this->response->item($payment, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $payment = Payment::create($request->all());
  47 +
  48 + return $this->response->created(url('api/payments/'.$payment->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $payment
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Payment $payment, Request $request)
  59 + {
  60 + $payment->update($request->all());
  61 +
  62 + return $this->response->item($payment->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Payment $payment
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Payment $payment)
  72 + {
  73 + $payment->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/Api/Expenses/Vendors.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Expenses/Vendors.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Expenses;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Expense\Vendor as Request;
  7 +use App\Models\Expense\Vendor;
  8 +use App\Transformers\Expense\Vendor as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Vendors extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $vendors = Vendor::collect();
  23 +
  24 + return $this->response->paginator($vendors, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param int|string $id
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show($id)
  34 + {
  35 + // Check if we're querying by id or email
  36 + if (is_numeric($id)) {
  37 + $vendor = Vendor::find($id);
  38 + } else {
  39 + $vendor = Vendor::where('email', $id)->first();
  40 + }
  41 +
  42 + return $this->response->item($vendor, new Transformer());
  43 + }
  44 +
  45 + /**
  46 + * Store a newly created resource in storage.
  47 + *
  48 + * @param $request
  49 + * @return \Dingo\Api\Http\Response
  50 + */
  51 + public function store(Request $request)
  52 + {
  53 + $vendor = Vendor::create($request->all());
  54 +
  55 + return $this->response->created(url('api/vendors/'.$vendor->id));
  56 + }
  57 +
  58 + /**
  59 + * Update the specified resource in storage.
  60 + *
  61 + * @param $vendor
  62 + * @param $request
  63 + * @return \Dingo\Api\Http\Response
  64 + */
  65 + public function update(Vendor $vendor, Request $request)
  66 + {
  67 + $vendor->update($request->all());
  68 +
  69 + return $this->response->item($vendor->fresh(), new Transformer());
  70 + }
  71 +
  72 + /**
  73 + * Remove the specified resource from storage.
  74 + *
  75 + * @param Vendor $vendor
  76 + * @return \Dingo\Api\Http\Response
  77 + */
  78 + public function destroy(Vendor $vendor)
  79 + {
  80 + $vendor->delete();
  81 +
  82 + return $this->response->noContent();
  83 + }
  84 +}
... ...
app/Http/Controllers/Api/Incomes/Customers.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Incomes/Customers.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Incomes;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Income\Customer as Request;
  7 +use App\Models\Income\Customer;
  8 +use App\Transformers\Income\Customer as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Customers extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $customers = Customer::collect();
  23 +
  24 + return $this->response->paginator($customers, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param int|string $id
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show($id)
  34 + {
  35 + // Check if we're querying by id or email
  36 + if (is_numeric($id)) {
  37 + $customer = Customer::find($id);
  38 + } else {
  39 + $customer = Customer::where('email', $id)->first();
  40 + }
  41 +
  42 + return $this->response->item($customer, new Transformer());
  43 + }
  44 +
  45 + /**
  46 + * Store a newly created resource in storage.
  47 + *
  48 + * @param $request
  49 + * @return \Dingo\Api\Http\Response
  50 + */
  51 + public function store(Request $request)
  52 + {
  53 + $customer = Customer::create($request->all());
  54 +
  55 + return $this->response->created(url('api/customers/'.$customer->id));
  56 + }
  57 +
  58 + /**
  59 + * Update the specified resource in storage.
  60 + *
  61 + * @param $customer
  62 + * @param $request
  63 + * @return \Dingo\Api\Http\Response
  64 + */
  65 + public function update(Customer $customer, Request $request)
  66 + {
  67 + $customer->update($request->all());
  68 +
  69 + return $this->response->item($customer->fresh(), new Transformer());
  70 + }
  71 +
  72 + /**
  73 + * Remove the specified resource from storage.
  74 + *
  75 + * @param Customer $customer
  76 + * @return \Dingo\Api\Http\Response
  77 + */
  78 + public function destroy(Customer $customer)
  79 + {
  80 + $customer->delete();
  81 +
  82 + return $this->response->noContent();
  83 + }
  84 +}
... ...
app/Http/Controllers/Api/Incomes/InvoicePayments.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Incomes/InvoicePayments.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Incomes;
  4 +
  5 +use App\Http\Requests\Income\InvoicePayment as Request;
  6 +use App\Models\Income\Invoice;
  7 +use App\Models\Income\InvoiceHistory;
  8 +use App\Models\Income\InvoicePayment;
  9 +use App\Models\Setting\Currency;
  10 +use App\Traits\DateTime;
  11 +use App\Transformers\Income\InvoicePayments as Transformer;
  12 +use Date;
  13 +use Dingo\Api\Routing\Helpers;
  14 +use Illuminate\Foundation\Bus\DispatchesJobs;
  15 +use Illuminate\Routing\Controller as BaseController;
  16 +use Illuminate\Foundation\Validation\ValidatesRequests;
  17 +use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  18 +
  19 +class InvoicePayments extends BaseController
  20 +{
  21 + use DateTime, Helpers, AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  22 +
  23 + /**
  24 + * Display a listing of the resource.
  25 + *
  26 + * @param $invoice_id
  27 + * @return \Dingo\Api\Http\Response
  28 + */
  29 + public function index($invoice_id)
  30 + {
  31 + $invoice_payments = InvoicePayment::where('invoice_id', $invoice_id)->get();
  32 +
  33 + return $this->response->collection($invoice_payments, new Transformer());
  34 + }
  35 +
  36 + /**
  37 + * Display the specified resource.
  38 + *
  39 + * @param $invoice_id
  40 + * @param $id
  41 + * @return \Dingo\Api\Http\Response
  42 + */
  43 + public function show($invoice_id, $id)
  44 + {
  45 + $invoice_payment = InvoicePayment::find($id);
  46 +
  47 + return $this->response->item($invoice_payment, new Transformer());
  48 + }
  49 +
  50 + /**
  51 + * Store a newly created resource in storage.
  52 + *
  53 + * @param $invoice_id
  54 + * @param $request
  55 + * @return \Dingo\Api\Http\Response
  56 + */
  57 + public function store($invoice_id, Request $request)
  58 + {
  59 + // Get currency object
  60 + $currency = Currency::where('code', $request['currency_code'])->first();
  61 +
  62 + $request['currency_code'] = $currency->code;
  63 + $request['currency_rate'] = $currency->rate;
  64 +
  65 + $request['invoice_id'] = $invoice_id;
  66 +
  67 + $invoice = Invoice::find($invoice_id);
  68 +
  69 + if ($request['currency_code'] == $invoice->currency_code) {
  70 + if ($request['amount'] > $invoice->amount) {
  71 + return $this->response->noContent();
  72 + } elseif ($request['amount'] == $invoice->amount) {
  73 + $invoice->invoice_status_code = 'paid';
  74 + } else {
  75 + $invoice->invoice_status_code = 'partial';
  76 + }
  77 + } else {
  78 + $request_invoice = new Invoice();
  79 +
  80 + $request_invoice->amount = (float) $request['amount'];
  81 + $request_invoice->currency_code = $currency->code;
  82 + $request_invoice->currency_rate = $currency->rate;
  83 +
  84 + $amount = $request_invoice->getConvertedAmount();
  85 +
  86 + if ($amount > $invoice->amount) {
  87 + return $this->response->noContent();
  88 + } elseif ($amount == $invoice->amount) {
  89 + $invoice->invoice_status_code = 'paid';
  90 + } else {
  91 + $invoice->invoice_status_code = 'partial';
  92 + }
  93 + }
  94 +
  95 + $invoice->save();
  96 +
  97 + $invoice_payment = InvoicePayment::create($request->input());
  98 +
  99 + $request['status_code'] = $invoice->invoice_status_code;
  100 + $request['notify'] = 0;
  101 +
  102 + $desc_date = Date::parse($request['paid_at'])->format($this->getCompanyDateFormat());
  103 + $desc_amount = money((float) $request['amount'], $request['currency_code'], true)->format();
  104 + $request['description'] = $desc_date . ' ' . $desc_amount;
  105 +
  106 + InvoiceHistory::create($request->input());
  107 +
  108 + return $this->response->created(url('api/invoices/' . $invoice_id . '/payments' . $invoice_payment->id));
  109 + }
  110 +
  111 + /**
  112 + * Remove the specified resource from storage.
  113 + *
  114 + * @param $invoice_id
  115 + * @param $id
  116 + * @return \Dingo\Api\Http\Response
  117 + */
  118 + public function destroy($invoice_id, $id)
  119 + {
  120 + $invoice_payment = InvoicePayment::find($id);
  121 +
  122 + $invoice_payment->delete();
  123 +
  124 + return $this->response->noContent();
  125 + }
  126 +}
... ...
app/Http/Controllers/Api/Incomes/Invoices.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Incomes/Invoices.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Incomes;
  4 +
  5 +use App\Events\InvoiceCreated;
  6 +use App\Events\InvoiceUpdated;
  7 +use App\Http\Controllers\ApiController;
  8 +use App\Http\Requests\Income\Invoice as Request;
  9 +use App\Models\Income\Invoice;
  10 +use App\Models\Income\InvoiceHistory;
  11 +use App\Models\Income\InvoiceItem;
  12 +use App\Models\Income\InvoicePayment;
  13 +use App\Models\Income\InvoiceTotal;
  14 +use App\Models\Common\Item;
  15 +use App\Models\Setting\Tax;
  16 +use App\Notifications\Common\Item as ItemNotification;
  17 +use App\Transformers\Income\Invoice as Transformer;
  18 +use Dingo\Api\Routing\Helpers;
  19 +
  20 +class Invoices extends ApiController
  21 +{
  22 + use Helpers;
  23 +
  24 + /**
  25 + * Display a listing of the resource.
  26 + *
  27 + * @return \Dingo\Api\Http\Response
  28 + */
  29 + public function index()
  30 + {
  31 + $invoices = Invoice::with(['customer', 'status', 'items', 'payments', 'histories'])->collect();
  32 +
  33 + return $this->response->paginator($invoices, new Transformer());
  34 + }
  35 +
  36 + /**
  37 + * Display the specified resource.
  38 + *
  39 + * @param $id
  40 + * @return \Dingo\Api\Http\Response
  41 + */
  42 + public function show($id)
  43 + {
  44 + // Check if we're querying by id or number
  45 + if (is_numeric($id)) {
  46 + $invoice = Invoice::find($id);
  47 + } else {
  48 + $invoice = Invoice::where('invoice_number', $id)->first();
  49 + }
  50 +
  51 + return $this->response->item($invoice, new Transformer());
  52 + }
  53 +
  54 + /**
  55 + * Store a newly created resource in storage.
  56 + *
  57 + * @param $request
  58 + * @return \Dingo\Api\Http\Response
  59 + */
  60 + public function store(Request $request)
  61 + {
  62 + if (empty($request['amount'])) {
  63 + $request['amount'] = 0;
  64 + }
  65 +
  66 + $invoice = Invoice::create($request->all());
  67 +
  68 + $taxes = [];
  69 + $tax_total = 0;
  70 + $sub_total = 0;
  71 +
  72 + $invoice_item = array();
  73 + $invoice_item['company_id'] = $request['company_id'];
  74 + $invoice_item['invoice_id'] = $invoice->id;
  75 +
  76 + if ($request['item']) {
  77 + foreach ($request['item'] as $item) {
  78 + $item_id = 0;
  79 + $item_sku = '';
  80 +
  81 + if (!empty($item['item_id'])) {
  82 + $item_object = Item::find($item['item_id']);
  83 +
  84 + $item_id = $item['item_id'];
  85 +
  86 + $item['name'] = $item_object->name;
  87 + $item_sku = $item_object->sku;
  88 +
  89 + // Decrease stock (item sold)
  90 + $item_object->quantity -= $item['quantity'];
  91 + $item_object->save();
  92 +
  93 + // Notify users if out of stock
  94 + if ($item_object->quantity == 0) {
  95 + foreach ($item_object->company->users as $user) {
  96 + if (!$user->can('read-notifications')) {
  97 + continue;
  98 + }
  99 +
  100 + $user->notify(new ItemNotification($item_object));
  101 + }
  102 + }
  103 + } elseif (!empty($item['sku'])) {
  104 + $item_sku = $item['sku'];
  105 + }
  106 +
  107 + $tax = $tax_id = 0;
  108 +
  109 + if (!empty($item['tax_id'])) {
  110 + $tax_object = Tax::find($item['tax_id']);
  111 +
  112 + $tax_id = $item['tax_id'];
  113 +
  114 + $tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
  115 + } elseif (!empty($item['tax'])) {
  116 + $tax = $item['tax'];
  117 + }
  118 +
  119 + $invoice_item['item_id'] = $item_id;
  120 + $invoice_item['name'] = str_limit($item['name'], 180, '');
  121 + $invoice_item['sku'] = $item_sku;
  122 + $invoice_item['quantity'] = $item['quantity'];
  123 + $invoice_item['price'] = $item['price'];
  124 + $invoice_item['tax'] = $tax;
  125 + $invoice_item['tax_id'] = $tax_id;
  126 + $invoice_item['total'] = $item['price'] * $item['quantity'];
  127 +
  128 + InvoiceItem::create($invoice_item);
  129 +
  130 + if (isset($tax_object)) {
  131 + if (array_key_exists($tax_object->id, $taxes)) {
  132 + $taxes[$tax_object->id]['amount'] += $tax;
  133 + } else {
  134 + $taxes[$tax_object->id] = [
  135 + 'name' => $tax_object->name,
  136 + 'amount' => $tax
  137 + ];
  138 + }
  139 + }
  140 +
  141 + $tax_total += $tax;
  142 + $sub_total += $invoice_item['total'];
  143 +
  144 + unset($item_object);
  145 + unset($tax_object);
  146 + }
  147 + }
  148 +
  149 + if (empty($request['amount'])) {
  150 + $request['amount'] = $sub_total + $tax_total;
  151 + }
  152 +
  153 + $invoice->update($request->input());
  154 +
  155 + // Add invoice totals
  156 + $this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total);
  157 +
  158 + $request['invoice_id'] = $invoice->id;
  159 + $request['status_code'] = $request['invoice_status_code'];
  160 + $request['notify'] = 0;
  161 + $request['description'] = trans('messages.success.added', ['type' => $request['invoice_number']]);
  162 +
  163 + InvoiceHistory::create($request->input());
  164 +
  165 + // Update next invoice number
  166 + $next = setting('general.invoice_number_next', 1) + 1;
  167 + setting(['general.invoice_number_next' => $next]);
  168 + setting()->save();
  169 +
  170 + // Fire the event to make it extendible
  171 + event(new InvoiceCreated($invoice));
  172 +
  173 + return $this->response->created(url('api/invoices/'.$invoice->id));
  174 + }
  175 +
  176 + /**
  177 + * Update the specified resource in storage.
  178 + *
  179 + * @param $invoice
  180 + * @param $request
  181 + * @return \Dingo\Api\Http\Response
  182 + */
  183 + public function update(Invoice $invoice, Request $request)
  184 + {
  185 + $taxes = [];
  186 + $tax_total = 0;
  187 + $sub_total = 0;
  188 +
  189 + $invoice_item = array();
  190 + $invoice_item['company_id'] = $request['company_id'];
  191 + $invoice_item['invoice_id'] = $invoice->id;
  192 +
  193 + if ($request['item']) {
  194 + InvoiceItem::where('invoice_id', $invoice->id)->delete();
  195 +
  196 + foreach ($request['item'] as $item) {
  197 + $item_id = 0;
  198 + $item_sku = '';
  199 +
  200 + if (!empty($item['item_id'])) {
  201 + $item_object = Item::find($item['item_id']);
  202 +
  203 + $item_id = $item['item_id'];
  204 +
  205 + $item['name'] = $item_object->name;
  206 + $item_sku = $item_object->sku;
  207 + } elseif (!empty($item['sku'])) {
  208 + $item_sku = $item['sku'];
  209 + }
  210 +
  211 + $tax = $tax_id = 0;
  212 +
  213 + if (!empty($item['tax_id'])) {
  214 + $tax_object = Tax::find($item['tax_id']);
  215 +
  216 + $tax_id = $item['tax_id'];
  217 +
  218 + $tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
  219 + } elseif (!empty($item['tax'])) {
  220 + $tax = $item['tax'];
  221 + }
  222 +
  223 + $invoice_item['item_id'] = $item_id;
  224 + $invoice_item['name'] = str_limit($item['name'], 180, '');
  225 + $invoice_item['sku'] = $item_sku;
  226 + $invoice_item['quantity'] = $item['quantity'];
  227 + $invoice_item['price'] = $item['price'];
  228 + $invoice_item['tax'] = $tax;
  229 + $invoice_item['tax_id'] = $tax_id;
  230 + $invoice_item['total'] = $item['price'] * $item['quantity'];
  231 +
  232 + $request['amount'] += $invoice_item['total'];
  233 +
  234 + InvoiceItem::create($invoice_item);
  235 +
  236 + if (isset($tax_object)) {
  237 + if (array_key_exists($tax_object->id, $taxes)) {
  238 + $taxes[$tax_object->id]['amount'] += $tax;
  239 + } else {
  240 + $taxes[$tax_object->id] = [
  241 + 'name' => $tax_object->name,
  242 + 'amount' => $tax
  243 + ];
  244 + }
  245 + }
  246 +
  247 + $tax_total += $tax;
  248 + $sub_total += $invoice_item['total'];
  249 +
  250 + unset($item_object);
  251 + unset($tax_object);
  252 + }
  253 + }
  254 +
  255 + if (empty($request['amount'])) {
  256 + $request['amount'] = $sub_total + $tax_total;
  257 + }
  258 +
  259 + $invoice->update($request->input());
  260 +
  261 + // Delete previous invoice totals
  262 + InvoiceTotal::where('invoice_id', $invoice->id)->delete();
  263 +
  264 + $this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total);
  265 +
  266 + // Fire the event to make it extendible
  267 + event(new InvoiceUpdated($invoice));
  268 +
  269 + return $this->response->item($invoice->fresh(), new Transformer());
  270 + }
  271 +
  272 + /**
  273 + * Remove the specified resource from storage.
  274 + *
  275 + * @param Invoice $invoice
  276 + * @return \Dingo\Api\Http\Response
  277 + */
  278 + public function destroy(Invoice $invoice)
  279 + {
  280 + $invoice->delete();
  281 +
  282 + InvoiceItem::where('invoice_id', $invoice->id)->delete();
  283 + InvoicePayment::where('invoice_id', $invoice->id)->delete();
  284 + InvoiceHistory::where('invoice_id', $invoice->id)->delete();
  285 +
  286 + return $this->response->noContent();
  287 + }
  288 +
  289 + protected function addTotals($invoice, $request, $taxes, $sub_total, $tax_total) {
  290 + // Add invoice total taxes
  291 + if ($request['totals']) {
  292 + $sort_order = 1;
  293 +
  294 + foreach ($request['totals'] as $total) {
  295 + if (!empty($total['sort_order'])) {
  296 + $sort_order = $total['sort_order'];
  297 + }
  298 +
  299 + $invoice_total = [
  300 + 'company_id' => $request['company_id'],
  301 + 'invoice_id' => $invoice->id,
  302 + 'code' => $total['code'],
  303 + 'name' => $total['name'],
  304 + 'amount' => $total['amount'],
  305 + 'sort_order' => $sort_order,
  306 + ];
  307 +
  308 + InvoiceTotal::create($invoice_total);
  309 +
  310 + if (empty($total['sort_order'])) {
  311 + $sort_order++;
  312 + }
  313 + }
  314 + } else {
  315 + // Added invoice total sub total
  316 + $invoice_sub_total = [
  317 + 'company_id' => $request['company_id'],
  318 + 'invoice_id' => $invoice->id,
  319 + 'code' => 'sub_total',
  320 + 'name' => 'invoices.sub_total',
  321 + 'amount' => $sub_total,
  322 + 'sort_order' => 1,
  323 + ];
  324 +
  325 + InvoiceTotal::create($invoice_sub_total);
  326 +
  327 + $sort_order = 2;
  328 +
  329 + // Added invoice total taxes
  330 + if ($taxes) {
  331 + foreach ($taxes as $tax) {
  332 + $invoice_tax_total = [
  333 + 'company_id' => $request['company_id'],
  334 + 'invoice_id' => $invoice->id,
  335 + 'code' => 'tax',
  336 + 'name' => $tax['name'],
  337 + 'amount' => $tax['amount'],
  338 + 'sort_order' => $sort_order,
  339 + ];
  340 +
  341 + InvoiceTotal::create($invoice_tax_total);
  342 +
  343 + $sort_order++;
  344 + }
  345 + }
  346 +
  347 + // Added invoice total total
  348 + $invoice_total = [
  349 + 'company_id' => $request['company_id'],
  350 + 'invoice_id' => $invoice->id,
  351 + 'code' => 'total',
  352 + 'name' => 'invoices.total',
  353 + 'amount' => $sub_total + $tax_total,
  354 + 'sort_order' => $sort_order,
  355 + ];
  356 +
  357 + InvoiceTotal::create($invoice_total);
  358 + }
  359 + }
  360 +}
... ...
app/Http/Controllers/Api/Incomes/Revenues.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Incomes/Revenues.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Incomes;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Income\Revenue as Request;
  7 +use App\Models\Income\Revenue;
  8 +use App\Transformers\Income\Revenue as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Revenues extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $revenues = Revenue::with(['account', 'customer', 'category'])->collect();
  23 +
  24 + return $this->response->paginator($revenues, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Revenue $revenue
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Revenue $revenue)
  34 + {
  35 + return $this->response->item($revenue, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $revenue = Revenue::create($request->all());
  47 +
  48 + return $this->response->created(url('api/revenues/'.$revenue->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $revenue
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Revenue $revenue, Request $request)
  59 + {
  60 + $revenue->update($request->all());
  61 +
  62 + return $this->response->item($revenue->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Revenue $revenue
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Revenue $revenue)
  72 + {
  73 + $revenue->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/Api/Settings/Categories.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Settings/Categories.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Settings;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Setting\Category as Request;
  7 +use App\Models\Setting\Category;
  8 +use App\Transformers\Setting\Category as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Categories extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $categories = Category::collect();
  23 +
  24 + return $this->response->paginator($categories, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Category $category
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Category $category)
  34 + {
  35 + return $this->response->item($category, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $category = Category::create($request->all());
  47 +
  48 + return $this->response->created(url('api/categories/'.$category->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $category
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Category $category, Request $request)
  59 + {
  60 + $category->update($request->all());
  61 +
  62 + return $this->response->item($category->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Category $category
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Category $category)
  72 + {
  73 + $category->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/Api/Settings/Currencies.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Settings/Currencies.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Settings;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Setting\Currency as Request;
  7 +use App\Models\Setting\Currency;
  8 +use App\Transformers\Setting\Currency as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Currencies extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $currencies = Currency::collect();
  23 +
  24 + return $this->response->paginator($currencies, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Currency $currency
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Currency $currency)
  34 + {
  35 + return $this->response->item($currency, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $currency = Currency::create($request->all());
  47 +
  48 + return $this->response->created(url('api/currencies/'.$currency->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $currency
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Currency $currency, Request $request)
  59 + {
  60 + $currency->update($request->all());
  61 +
  62 + return $this->response->item($currency->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Currency $currency
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Currency $currency)
  72 + {
  73 + $currency->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/Api/Settings/Settings.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Settings/Settings.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Settings;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Setting\Setting as Request;
  7 +use App\Models\Setting\Setting;
  8 +use App\Transformers\Setting\Setting as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Settings extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $settings = Setting::all();
  23 +
  24 + return $this->response->collection($settings, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param int|string $id
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show($id)
  34 + {
  35 + // Check if we're querying by id or key
  36 + if (is_numeric($id)) {
  37 + $setting = Setting::find($id);
  38 + } else {
  39 + $setting = Setting::where('key', $id)->first();
  40 + }
  41 +
  42 + return $this->response->item($setting, new Transformer());
  43 + }
  44 +
  45 + /**
  46 + * Store a newly created resource in storage.
  47 + *
  48 + * @param $request
  49 + * @return \Dingo\Api\Http\Response
  50 + */
  51 + public function store(Request $request)
  52 + {
  53 + $setting = Setting::create($request->all());
  54 +
  55 + return $this->response->created(url('api/settings/'.$setting->id));
  56 + }
  57 +
  58 + /**
  59 + * Update the specified resource in storage.
  60 + *
  61 + * @param $setting
  62 + * @param $request
  63 + * @return \Dingo\Api\Http\Response
  64 + */
  65 + public function update(Setting $setting, Request $request)
  66 + {
  67 + $setting->update($request->all());
  68 +
  69 + return $this->response->item($setting->fresh(), new Transformer());
  70 + }
  71 +
  72 + /**
  73 + * Remove the specified resource from storage.
  74 + *
  75 + * @param Setting $setting
  76 + * @return \Dingo\Api\Http\Response
  77 + */
  78 + public function destroy(Setting $setting)
  79 + {
  80 + $setting->delete();
  81 +
  82 + return $this->response->noContent();
  83 + }
  84 +}
... ...
app/Http/Controllers/Api/Settings/Taxes.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Api/Settings/Taxes.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api\Settings;
  4 +
  5 +use App\Http\Controllers\ApiController;
  6 +use App\Http\Requests\Setting\Tax as Request;
  7 +use App\Models\Setting\Tax;
  8 +use App\Transformers\Setting\Tax as Transformer;
  9 +use Dingo\Api\Routing\Helpers;
  10 +
  11 +class Taxes extends ApiController
  12 +{
  13 + use Helpers;
  14 +
  15 + /**
  16 + * Display a listing of the resource.
  17 + *
  18 + * @return \Dingo\Api\Http\Response
  19 + */
  20 + public function index()
  21 + {
  22 + $taxes = Tax::collect();
  23 +
  24 + return $this->response->paginator($taxes, new Transformer());
  25 + }
  26 +
  27 + /**
  28 + * Display the specified resource.
  29 + *
  30 + * @param Tax $tax
  31 + * @return \Dingo\Api\Http\Response
  32 + */
  33 + public function show(Tax $tax)
  34 + {
  35 + return $this->response->item($tax, new Transformer());
  36 + }
  37 +
  38 + /**
  39 + * Store a newly created resource in storage.
  40 + *
  41 + * @param $request
  42 + * @return \Dingo\Api\Http\Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + $tax = Tax::create($request->all());
  47 +
  48 + return $this->response->created(url('api/taxes/'.$tax->id));
  49 + }
  50 +
  51 + /**
  52 + * Update the specified resource in storage.
  53 + *
  54 + * @param $tax
  55 + * @param $request
  56 + * @return \Dingo\Api\Http\Response
  57 + */
  58 + public function update(Tax $tax, Request $request)
  59 + {
  60 + $tax->update($request->all());
  61 +
  62 + return $this->response->item($tax->fresh(), new Transformer());
  63 + }
  64 +
  65 + /**
  66 + * Remove the specified resource from storage.
  67 + *
  68 + * @param Tax $tax
  69 + * @return \Dingo\Api\Http\Response
  70 + */
  71 + public function destroy(Tax $tax)
  72 + {
  73 + $tax->delete();
  74 +
  75 + return $this->response->noContent();
  76 + }
  77 +}
... ...
app/Http/Controllers/ApiController.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/ApiController.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers;
  4 +
  5 +use Dingo\Api\Exception\ResourceException;
  6 +use Illuminate\Http\Request;
  7 +
  8 +class ApiController extends Controller
  9 +{
  10 + /**
  11 + * Create the response for when a request fails validation.
  12 + *
  13 + * @param \Illuminate\Http\Request $request
  14 + * @param array $errors
  15 + * @return \Symfony\Component\HttpFoundation\Response
  16 + */
  17 + protected function buildFailedValidationResponse(Request $request, array $errors)
  18 + {
  19 + if ($request->expectsJson()) {
  20 + throw new ResourceException('Validation Error', $errors);
  21 + }
  22 +
  23 + return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
  24 + }
  25 +}
... ...
app/Http/Controllers/Auth/Forgot.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Auth/Forgot.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Auth;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +
  7 +use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
  8 +use Illuminate\Http\Request;
  9 +use Illuminate\Support\Facades\Password;
  10 +
  11 +class Forgot extends Controller
  12 +{
  13 + /*
  14 + |--------------------------------------------------------------------------
  15 + | Password Reset Controller
  16 + |--------------------------------------------------------------------------
  17 + |
  18 + | This controller is responsible for handling password reset emails and
  19 + | includes a trait which assists in sending these notifications from
  20 + | your application to your users. Feel free to explore this trait.
  21 + |
  22 + */
  23 +
  24 + use SendsPasswordResetEmails;
  25 +
  26 + /**
  27 + * Where to redirect users after reset.
  28 + *
  29 + * @var string
  30 + */
  31 + protected $redirectTo = 'auth/forgot';
  32 +
  33 + /**
  34 + * Create a new controller instance.
  35 + *
  36 + * @return void
  37 + */
  38 + public function __construct()
  39 + {
  40 + $this->middleware('guest');
  41 + }
  42 +
  43 + /**
  44 + * Display the form to request a password reset link.
  45 + *
  46 + * @return \Illuminate\Http\Response
  47 + */
  48 + public function create()
  49 + {
  50 + return view('auth.forgot.create');
  51 + }
  52 +
  53 + /**
  54 + * Send a reset link to the given user.
  55 + *
  56 + * @param \Illuminate\Http\Request $request
  57 + * @return \Illuminate\Http\RedirectResponse
  58 + */
  59 + public function store(Request $request)
  60 + {
  61 + $this->validateEmail($request);
  62 +
  63 + // We will send the password reset link to this user. Once we have attempted
  64 + // to send the link, we will examine the response then see the message we
  65 + // need to show to the user. Finally, we'll send out a proper response.
  66 + $response = $this->broker()->sendResetLink(
  67 + $request->only('email')
  68 + );
  69 +
  70 + return $response == Password::RESET_LINK_SENT
  71 + ? $this->sendResetLinkResponse($response)
  72 + : $this->sendResetLinkFailedResponse($request, $response);
  73 + }
  74 +
  75 + /**
  76 + * Get the response for a successful password reset link.
  77 + *
  78 + * @param string $response
  79 + * @return \Illuminate\Http\RedirectResponse
  80 + */
  81 + protected function sendResetLinkResponse($response)
  82 + {
  83 + flash(trans($response))->success();
  84 +
  85 + return redirect($this->redirectTo);
  86 + }
  87 +
  88 + /**
  89 + * Get the response for a failed password reset link.
  90 + *
  91 + * @param \Illuminate\Http\Request
  92 + * @param string $response
  93 + * @return \Illuminate\Http\RedirectResponse
  94 + */
  95 + protected function sendResetLinkFailedResponse(Request $request, $response)
  96 + {
  97 + return redirect($this->redirectTo)->withErrors(
  98 + ['email' => trans($response)]
  99 + );
  100 + }
  101 +}
... ...
app/Http/Controllers/Auth/Login.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Auth/Login.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Auth;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use Illuminate\Foundation\Auth\AuthenticatesUsers;
  7 +
  8 +class Login extends Controller
  9 +{
  10 + /*
  11 + |--------------------------------------------------------------------------
  12 + | Login Controller
  13 + |--------------------------------------------------------------------------
  14 + |
  15 + | This controller handles authenticating users for the application and
  16 + | redirecting them to your home screen. The controller uses a trait
  17 + | to conveniently provide its functionality to your applications.
  18 + |
  19 + */
  20 +
  21 + use AuthenticatesUsers;
  22 +
  23 + /**
  24 + * Where to redirect users after login.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $redirectTo = '/';
  29 +
  30 + /**
  31 + * Create a new controller instance.
  32 + *
  33 + * @return void
  34 + */
  35 + /*public function __construct()
  36 + {
  37 + $this->middleware('guest')->except('logout');
  38 + }*/
  39 + public function __construct()
  40 + {
  41 + $this->middleware('guest', ['except' => 'destroy']);
  42 + }
  43 +
  44 + public function create()
  45 + {
  46 + return view('auth.login.create');
  47 + }
  48 +
  49 + public function store()
  50 + {
  51 + // Attempt to login
  52 + if (!auth()->attempt(request(['email', 'password']))) {
  53 + flash(trans('auth.failed'))->error();
  54 +
  55 + return back();
  56 + }
  57 +
  58 + // Get user object
  59 + $user = auth()->user();
  60 +
  61 + // Check if user is enabled
  62 + if (!$user->enabled) {
  63 + $this->logout();
  64 +
  65 + flash(trans('auth.disabled'))->error();
  66 +
  67 + return redirect('auth/login');
  68 + }
  69 +
  70 + // Check if is customer
  71 + if ($user->customer) {
  72 + $path = session('url.intended', 'customers');
  73 +
  74 + // Path must start with 'customers' prefix
  75 + if (!str_contains($path, 'customers')) {
  76 + $path = 'customers';
  77 + }
  78 +
  79 + return redirect($path);
  80 + }
  81 +
  82 + return redirect('/');
  83 + }
  84 +
  85 + public function destroy()
  86 + {
  87 + $this->logout();
  88 +
  89 + return redirect('auth/login');
  90 + }
  91 +
  92 + public function logout()
  93 + {
  94 + auth()->logout();
  95 +
  96 + // Session destroy is required if stored in database
  97 + if (env('SESSION_DRIVER') == 'database') {
  98 + $request = app('Illuminate\Http\Request');
  99 + $request->session()->getHandler()->destroy($request->session()->getId());
  100 + }
  101 + }
  102 +}
... ...
app/Http/Controllers/Auth/Permissions.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Auth/Permissions.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Auth;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use App\Http\Requests\Auth\Permission as Request;
  7 +use App\Models\Auth\Permission;
  8 +
  9 +class Permissions extends Controller
  10 +{
  11 +
  12 + /**
  13 + * Display a listing of the resource.
  14 + *
  15 + * @return Response
  16 + */
  17 + public function index()
  18 + {
  19 + $permissions = Permission::collect();
  20 +
  21 + return view('auth.permissions.index', compact('permissions'));
  22 + }
  23 +
  24 + /**
  25 + * Show the form for creating a new resource.
  26 + *
  27 + * @return Response
  28 + */
  29 + public function create()
  30 + {
  31 + return view('auth.permissions.create');
  32 + }
  33 +
  34 + /**
  35 + * Store a newly created resource in storage.
  36 + *
  37 + * @param Request $request
  38 + *
  39 + * @return Response
  40 + */
  41 + public function store(Request $request)
  42 + {
  43 + // Create permission
  44 + $permission = Permission::create($request->all());
  45 +
  46 + $message = trans('messages.success.added', ['type' => trans_choice('general.permissions', 1)]);
  47 +
  48 + flash($message)->success();
  49 +
  50 + return redirect('auth/permissions');
  51 + }
  52 +
  53 + /**
  54 + * Show the form for editing the specified resource.
  55 + *
  56 + * @param Permission $permission
  57 + *
  58 + * @return Response
  59 + */
  60 + public function edit(Permission $permission)
  61 + {
  62 + return view('auth.permissions.edit', compact('permission'));
  63 + }
  64 +
  65 + /**
  66 + * Update the specified resource in storage.
  67 + *
  68 + * @param Permission $permission
  69 + * @param Request $request
  70 + *
  71 + * @return Response
  72 + */
  73 + public function update(Permission $permission, Request $request)
  74 + {
  75 + // Update permission
  76 + $permission->update($request->all());
  77 +
  78 + $message = trans('messages.success.updated', ['type' => trans_choice('general.permissions', 1)]);
  79 +
  80 + flash($message)->success();
  81 +
  82 + return redirect('auth/permissions');
  83 + }
  84 +
  85 + /**
  86 + * Remove the specified resource from storage.
  87 + *
  88 + * @param Permission $permission
  89 + *
  90 + * @return Response
  91 + */
  92 + public function destroy(Permission $permission)
  93 + {
  94 + $permission->delete();
  95 +
  96 + $message = trans('messages.success.deleted', ['type' => trans_choice('general.permissions', 1)]);
  97 +
  98 + flash($message)->success();
  99 +
  100 + return redirect('auth/permissions');
  101 + }
  102 +}
... ...
app/Http/Controllers/Auth/Reset.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Auth/Reset.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Auth;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use Illuminate\Foundation\Auth\ResetsPasswords;
  7 +use Illuminate\Http\Request;
  8 +use Illuminate\Support\Facades\Password;
  9 +use Illuminate\Support\Str;
  10 +
  11 +class Reset extends Controller
  12 +{
  13 + /*
  14 + |--------------------------------------------------------------------------
  15 + | Password Reset Controller
  16 + |--------------------------------------------------------------------------
  17 + |
  18 + | This controller is responsible for handling password reset requests
  19 + | and uses a simple trait to include this behavior. You're free to
  20 + | explore this trait and override any methods you wish to tweak.
  21 + |
  22 + */
  23 +
  24 + use ResetsPasswords;
  25 +
  26 + /**
  27 + * Where to redirect users after resetting their password.
  28 + *
  29 + * @var string
  30 + */
  31 + public $redirectTo = '/';
  32 +
  33 + /**
  34 + * Create a new controller instance.
  35 + *
  36 + * @return void
  37 + */
  38 + public function __construct()
  39 + {
  40 + $this->middleware('guest');
  41 + }
  42 +
  43 + public function create(Request $request, $token = null)
  44 + {
  45 + return view('auth.reset.create')->with(
  46 + ['token' => $token, 'email' => $request->email]
  47 + );
  48 + }
  49 +
  50 + public function store(Request $request)
  51 + {
  52 + $this->validate($request, $this->rules(), $this->validationErrorMessages());
  53 +
  54 + // Here we will attempt to reset the user's password. If it is successful we
  55 + // will update the password on an actual user model and persist it to the
  56 + // database. Otherwise we will parse the error and return the response.
  57 + $response = $this->broker()->reset(
  58 + $this->credentials($request), function ($user, $password) {
  59 + $this->resetPassword($user, $password);
  60 + }
  61 + );
  62 +
  63 + // If the password was successfully reset, we will redirect the user back to
  64 + // the application's home authenticated view. If there is an error we can
  65 + // redirect them back to where they came from with their error message.
  66 + return $response == Password::PASSWORD_RESET
  67 + ? $this->sendResetResponse($response)
  68 + : $this->sendResetFailedResponse($request, $response);
  69 + }
  70 +
  71 + /**
  72 + * Reset the given user's password.
  73 + *
  74 + * @param \Illuminate\Contracts\Auth\CanResetPassword $user
  75 + * @param string $password
  76 + * @return void
  77 + */
  78 + protected function resetPassword($user, $password)
  79 + {
  80 + $user->forceFill([
  81 + 'password' => $password,
  82 + 'remember_token' => Str::random(60),
  83 + ])->save();
  84 +
  85 + $this->guard()->login($user);
  86 + }
  87 +
  88 + /**
  89 + * Get the response for a successful password reset.
  90 + *
  91 + * @param string $response
  92 + * @return \Illuminate\Http\RedirectResponse
  93 + */
  94 + protected function sendResetResponse($response)
  95 + {
  96 + flash(trans($response))->success();
  97 +
  98 + return redirect($this->redirectTo);
  99 + }
  100 +
  101 + /**
  102 + * Get the response for a failed password reset.
  103 + *
  104 + * @param \Illuminate\Http\Request
  105 + * @param string $response
  106 + * @return \Illuminate\Http\RedirectResponse
  107 + */
  108 + protected function sendResetFailedResponse(Request $request, $response)
  109 + {
  110 + return redirect()->back()
  111 + ->withInput($request->only('email'))
  112 + ->withErrors(['email' => trans($response)]);
  113 + }
  114 +}
... ...
app/Http/Controllers/Auth/Roles.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Auth/Roles.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Auth;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use App\Http\Requests\Auth\Role as Request;
  7 +use App\Models\Auth\Permission;
  8 +use App\Models\Auth\Role;
  9 +
  10 +class Roles extends Controller
  11 +{
  12 +
  13 + /**
  14 + * Display a listing of the resource.
  15 + *
  16 + * @return Response
  17 + */
  18 + public function index()
  19 + {
  20 + $roles = Role::collect();
  21 +
  22 + return view('auth.roles.index', compact('roles'));
  23 + }
  24 +
  25 + /**
  26 + * Show the form for creating a new resource.
  27 + *
  28 + * @return Response
  29 + */
  30 + public function create()
  31 + {
  32 + $permissions = Permission::all();
  33 +
  34 + return view('auth.roles.create', compact('permissions'));
  35 + }
  36 +
  37 + /**
  38 + * Store a newly created resource in storage.
  39 + *
  40 + * @param Request $request
  41 + *
  42 + * @return Response
  43 + */
  44 + public function store(Request $request)
  45 + {
  46 + // Create role
  47 + $role = Role::create($request->all());
  48 +
  49 + // Attach permissions
  50 + $role->permissions()->attach($request['permissions']);
  51 +
  52 + $message = trans('messages.success.added', ['type' => trans_choice('general.roles', 1)]);
  53 +
  54 + flash($message)->success();
  55 +
  56 + return redirect('auth/roles');
  57 + }
  58 +
  59 + /**
  60 + * Show the form for editing the specified resource.
  61 + *
  62 + * @param Role $role
  63 + *
  64 + * @return Response
  65 + */
  66 + public function edit(Role $role)
  67 + {
  68 + //$permissions = Permission::all()->sortBy('display_name');
  69 + $permissions = Permission::all();
  70 +
  71 + $rolePermissions = $role->permissions->pluck('id', 'id')->toArray();
  72 +
  73 + return view('auth.roles.edit', compact('role', 'permissions', 'rolePermissions'));
  74 + }
  75 +
  76 + /**
  77 + * Update the specified resource in storage.
  78 + *
  79 + * @param Role $role
  80 + * @param Request $request
  81 + *
  82 + * @return Response
  83 + */
  84 + public function update(Role $role, Request $request)
  85 + {
  86 + // Update role
  87 + $role->update($request->all());
  88 +
  89 + // Sync permissions
  90 + $role->permissions()->sync($request['permissions']);
  91 +
  92 + $message = trans('messages.success.updated', ['type' => trans_choice('general.roles', 1)]);
  93 +
  94 + flash($message)->success();
  95 +
  96 + return redirect('auth/roles');
  97 + }
  98 +
  99 + /**
  100 + * Remove the specified resource from storage.
  101 + *
  102 + * @param Role $role
  103 + *
  104 + * @return Response
  105 + */
  106 + public function destroy(Role $role)
  107 + {
  108 + $role->delete();
  109 +
  110 + $message = trans('messages.success.deleted', ['type' => trans_choice('general.roles', 1)]);
  111 +
  112 + flash($message)->success();
  113 +
  114 + return redirect('auth/roles');
  115 + }
  116 +}
... ...
app/Http/Controllers/Auth/Users.php 0 โ†’ 100755
  1 +++ a/app/Http/Controllers/Auth/Users.php
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Auth;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use App\Http\Requests\Auth\User as Request;
  7 +use Illuminate\Http\Request as ARequest;
  8 +use App\Models\Auth\User;
  9 +use App\Models\Auth\Role;
  10 +use App\Traits\Uploads;
  11 +
  12 +use Auth;
  13 +
  14 +class Users extends Controller
  15 +{
  16 + use Uploads;
  17 +
  18 + /**
  19 + * Display a listing of the resource.
  20 + *
  21 + * @return Response
  22 + */
  23 + public function index()
  24 + {
  25 + $users = User::with('roles')->collect();
  26 +
  27 + $roles = collect(Role::all()->pluck('display_name', 'id'))
  28 + ->prepend(trans('general.all_type', ['type' => trans_choice('general.roles', 2)]), '');
  29 +
  30 + return view('auth.users.index', compact('users', 'roles'));
  31 + }
  32 +
  33 + /**
  34 + * Show the form for creating a new resource.
  35 + *
  36 + * @return Response
  37 + */
  38 + public function create()
  39 + {
  40 + $roles = Role::all()->reject(function ($r) {
  41 + return $r->hasPermission('read-customer-panel');
  42 + });
  43 +
  44 + $companies = Auth::user()->companies()->get()->sortBy('name');
  45 +
  46 + foreach ($companies as $company) {
  47 + $company->setSettings();
  48 + }
  49 +
  50 + return view('auth.users.create', compact('roles', 'companies'));
  51 + }
  52 +
  53 + /**
  54 + * Store a newly created resource in storage.
  55 + *
  56 + * @param Request $request
  57 + *
  58 + * @return Response
  59 + */
  60 + public function store(Request $request)
  61 + {
  62 + // Create user
  63 + $user = User::create($request->input());
  64 +
  65 + // Upload picture
  66 + if ($request->file('picture')) {
  67 + $media = $this->getMedia($request->file('picture'), 'users');
  68 +
  69 + $user->attachMedia($media, 'picture');
  70 + }
  71 +
  72 + // Attach roles
  73 + $user->roles()->attach($request['roles']);
  74 +
  75 + // Attach companies
  76 + $user->companies()->attach($request['companies']);
  77 +
  78 + $message = trans('messages.success.added', ['type' => trans_choice('general.users', 1)]);
  79 +
  80 + flash($message)->success();
  81 +
  82 + return redirect('auth/users');
  83 + }
  84 +
  85 + /**
  86 + * Show the form for editing the specified resource.
  87 + *
  88 + * @param User $user
  89 + *
  90 + * @return Response
  91 + */
  92 + public function edit(User $user)
  93 + {
  94 + if ($user->customer) {
  95 + // Show only roles with customer permission
  96 + $roles = Role::all()->reject(function ($r) {
  97 + return !$r->hasPermission('read-customer-panel');
  98 + });
  99 + } else {
  100 + // Don't show roles with customer permission
  101 + $roles = Role::all()->reject(function ($r) {
  102 + return $r->hasPermission('read-customer-panel');
  103 + });
  104 + }
  105 +
  106 + $companies = Auth::user()->companies()->get()->sortBy('name');
  107 +
  108 + foreach ($companies as $company) {
  109 + $company->setSettings();
  110 + }
  111 +
  112 + return view('auth.users.edit', compact('user', 'companies', 'roles'));
  113 + }
  114 +
  115 + /**
  116 + * Update the specified resource in storage.
  117 + *
  118 + * @param User $user
  119 + * @param Request $request
  120 + *
  121 + * @return Response
  122 + */
  123 + public function update(User $user, Request $request)
  124 + {
  125 + // Do not reset password if not entered/changed
  126 + if (empty($request['password'])) {
  127 + unset($request['password']);
  128 + unset($request['password_confirmation']);
  129 + }
  130 +
  131 + // Update user
  132 + $user->update($request->input());
  133 +
  134 + // Upload picture
  135 + if ($request->file('picture')) {
  136 + $media = $this->getMedia($request->file('picture'), 'users');
  137 +
  138 + $user->attachMedia($media, 'picture');
  139 + }
  140 +
  141 + // Sync roles
  142 + $user->roles()->sync($request['roles']);
  143 +
  144 + // Sync companies
  145 + $user->companies()->sync($request['companies']);
  146 +
  147 + $message = trans('messages.success.updated', ['type' => trans_choice('general.users', 1)]);
  148 +
  149 + flash($message)->success();
  150 +
  151 + return redirect('auth/users');
  152 + }
  153 +
  154 + /**
  155 + * Enable the specified resource.
  156 + *
  157 + * @param User $user
  158 + *
  159 + * @return Response
  160 + */
  161 + public function enable(User $user)
  162 + {
  163 + $user->enabled = 1;
  164 + $user->save();
  165 +
  166 + $message = trans('messages.success.enabled', ['type' => trans_choice('general.users', 1)]);
  167 +
  168 + flash($message)->success();
  169 +
  170 + return redirect()->route('users.index');
  171 + }
  172 +
  173 + /**
  174 + * Disable the specified resource.
  175 + *
  176 + * @param User $user
  177 + *
  178 + * @return Response
  179 + */
  180 + public function disable(User $user)
  181 + {
  182 + $user->enabled = 0;
  183 + $user->save();
  184 +
  185 + $message = trans('messages.success.disabled', ['type' => trans_choice('general.users', 1)]);
  186 +
  187 + flash($message)->success();
  188 +
  189 + return redirect()->route('users.index');
  190 + }
  191 +
  192 + /**
  193 + * Remove the specified resource from storage.
  194 + *
  195 + * @param User $user
  196 + *
  197 + * @return Response
  198 + */
  199 + public function destroy(User $user)
  200 + {
  201 + // Can't delete yourself
  202 + if ($user->id == \Auth::user()->id) {
  203 + $message = trans('auth.error.self_delete');
  204 +
  205 + flash($message)->error();
  206 +
  207 + return redirect('auth/users');
  208 + }
  209 +
  210 + $user->delete();
  211 +
  212 + $message = trans('messages.success.deleted', ['type' => trans_choice('general.users', 1)]);
  213 +
  214 + flash($message)->success();
  215 +
  216 + return redirect('auth/users');
  217 + }
  218 +
  219 + /**
  220 + * Mark upcoming bills notifications are read and redirect to bills page.
  221 + *
  222 + * @param User $user
  223 + *
  224 + * @return Response
  225 + */
  226 + public function readUpcomingBills(User $user)
  227 + {
  228 + // Mark bill notifications as read
  229 + foreach ($user->unreadNotifications as $notification) {
  230 + // Not a bill notification
  231 + if ($notification->getAttribute('type') != 'App\Notifications\Expense\Bill') {
  232 + continue;
  233 + }
  234 +
  235 + $notification->markAsRead();
  236 + }
  237 +
  238 + // Redirect to bills
  239 + return redirect('expenses/bills');
  240 + }
  241 +
  242 + /**
  243 + * Mark overdue invoices notifications are read and redirect to invoices page.
  244 + *
  245 + * @param User $user
  246 + *
  247 + * @return Response
  248 + */
  249 + public function readOverdueInvoices(User $user)
  250 + {
  251 + // Mark invoice notifications as read
  252 + foreach ($user->unreadNotifications as $notification) {
  253 + // Not an invoice notification
  254 + if ($notification->getAttribute('type') != 'App\Notifications\Income\Invoice') {
  255 + continue;
  256 + }
  257 +
  258 + $notification->markAsRead();
  259 + }
  260 +
  261 + // Redirect to invoices
  262 + return redirect('incomes/invoices');
  263 + }
  264 +
  265 + /**
  266 + * Mark items out of stock notifications are read and redirect to items page.
  267 + *
  268 + * @param User $user
  269 + *
  270 + * @return Response
  271 + */
  272 + public function readItemsOutOfStock(User $user)
  273 + {
  274 + // Mark item notifications as read
  275 + foreach ($user->unreadNotifications as $notification) {
  276 + // Not an item notification
  277 + if ($notification->getAttribute('type') != 'App\Notifications\Common\Item') {
  278 + continue;
  279 + }
  280 +
  281 + $notification->markAsRead();
  282 + }
  283 +
  284 + // Redirect to items
  285 + return redirect('common/items');
  286 + }
  287 +
  288 + public function autocomplete(ARequest $request)
  289 + {
  290 + $user = false;
  291 + $data = false;
  292 +
  293 + $column = $request['column'];
  294 + $value = $request['value'];
  295 +
  296 + if (!empty($column) && !empty($value)) {
  297 + switch ($column) {
  298 + case 'id':
  299 + $user = User::find((int) $value);
  300 + break;
  301 + case 'email':
  302 + $user = User::where('email', $value)->first();
  303 + break;
  304 + default:
  305 + $user = User::where($column, $value)->first();
  306 + }
  307 +
  308 + $data = $user;
  309 + } elseif (!empty($column) && empty($value)) {
  310 + $data = trans('validation.required', ['attribute' => $column]);
  311 + }
  312 +
  313 + return response()->json([
  314 + 'errors' => ($user) ? false : true,
  315 + 'success' => ($user) ? true : false,
  316 + 'data' => $data
  317 + ]);
  318 + }
  319 +}
... ...